Git Basics

  1. Git is a distributed version control system, centralized version control systems like the SVN, git in local also maintains a local warehouse, so even if there is no network can work normally, as long as the final amend the own synchronization to the remote, and SVN is dependent on the network connection, and the bandwidth is very high.
  2. Git into work the workspace, the staging area stage | idnex, local repository (history) the local repository, remote warehouse remote repository.
    • Workspace: a place where code is normally stored. There are four file states: Untracked unmodified, unmodified, modified, staged.
      • Untracked: not tracked, typically a file added to the current warehouse that was not previously present in the warehouse; Such files can be added to the repository by modifying their state to passively through Git Add;

      • Unmodified: a file that has not been modified, usually the original file in the repository, without any action being performed; There are two places for such files:
        • Change the state of a file to modified.
        • Deletes the file from the repository with git rm file name –cache, that is, does not track the file and becomes untracked. Git rm
      • Modified: a file in a warehouse that has been modified;

      • Passage Ten: Passively stored files, usually submitted from a workspace via Git Add
    • Stage: temporary storage area, submits the contents of the workspace to the temporary state

git rm

  1. Git rm file: The workspace file will be deleted first, and the deletion will be recorded in the stage, which is equivalent to rm + git add.
    • Rm: The following figure shows rm operation and rollback:

    • Git rm:

  2. Git rm file –cache: Detach the file from the trace state to untracked.

Git checkout and Git reset

  1. Git checkout:

    • Git checkout file: Rollback a file from the staging area to your workspace. For example, you can make changes to a file that you don’t want to make, or you can delete it if the staging area doesn’t have the file.
    • Git checkout commit file: Rollback of a commit file overwrites the staging area and workspace.
  2. Git reset:

    • Git reset: Resets files in the staging area. For example, files added in can be pulled back through this method, or deleted.
    • Git reset –hard: resets the workspace and staging area as the last commit.
    • Git reset COMMIT: Set HEAD to commit, update staging, workspace unchanged.
    • Git reset –hard commit: Reverses the version to commit.

git stash

When development is interrupted and you don’t want to commit, stash can be used.

  1. Git stash: Place all workspace file changes in the Stash stash stack so you can pull, etc., and then pull them out.
  2. Git stash list: View the contents of the current stash;
  3. Git stash pop: Pull out what you saved.

git commit

Commit commits files from the staging area to the local repository history area.

  1. Git commit -m ‘message’ : commit a version.
  2. Git commit -a: Commits the files in the workspace directly to a version based on the last commit.
  3. Git commit -v: displays all diff information at commit time;
  4. Git commit — amend-m ‘message’ : a new commit is used to replace the last commit, and if nothing changes, it is used to rewrite the last commit.
  5. Git commit –amend [file1] [file2] : rewrites the last commit, including new file updates.

git ls-files

This command displays information about a file

  1. Git ls-files: View all cached files.
  2. Git ls-files-o: check for untraced files;
  3. Fit ls-files –modified: View the modified file.

Git init create a local git repository by using git init and git remote add origin [git address]. Git remote -v can be used to check the connection to the associated name and repository address.

Git remote remove git remote remove git remote remove Git push origin main (” main “); git push main (” main “); git push main (” main “); Git push –set-upstream: git push –set-upstream: git push –set-upstream: git push –set-upstream Branches in the repository are independent of each other and can be merged when functionality is developed.

Git clone [git address] Use git Clone to clone projects. –set-upstream connection is automatically established with clone. You do not need to specify a branch name (master or main is the clone branch). You also need to do git init for newly created branches.

Clone remote branch directly:

  1. Git clone [remote address] git fetch origin [remote address] git fetch origin Git checkout -b [local branch name] [host name]/[remote branch name
  2. Git clone -b

A new branch can split a new branch from the current branch based on the current branch. Create and switch with git checkout -b [branch name]

  1. Git checkout: Switch branches
  2. Git branch View local branches
  3. Git branch -r Displays remote branches
  4. Git branch -a views local and remote branches
  5. Git branch -d/ -d branch name Deletes a local branch
  6. Git push: delete the remote branch
  7. Git push [host name] –delete [remote branch name
  8. Git branch-dr only deletes trace, remote is not deleted
  9. Git branch –track [local branch name] [host name/remote branch name]
  10. Git branch –set-upstream — to () –set up a connection with a remote branch. If you want to commit, you need to use git commit origin.

The remote branch was deleted incorrectly. Procedure

Some remote branches may be deleted by mistake, so an emergency remedy is needed:

  1. Git reflog –date=iso found the first commit before deleting commitid
  2. Git checkout -b Local branch name (commitid
  3. Git push origin –set-upstream Upload version to remote and set tracing