Git command forward and reverse practical operation

Work area and cache area:

Forward:

git add [FileName] adds a single file to the cache

git add . Add multiple files to the cache

Reverse:

git reset HEAD [FileName] revokes a single file in the cache area, and the work area file is not affected

git reset HEAD . Undo multiple files in the cache area, and the files in the work area will not be affected

git checkout -- [FileName] revokes a single file in the workspace and replaces it with a cache file

git checkout -- . Undo multiple files in the workspace and replace them with cache files

Cache area and local warehouse:

Forward:

git commit -m "XXXX" Submit the buffer file to the local warehouse, XXXX is the remark information

Reverse:

git reset --hard [commitID] The local warehouse version is rolled back, and all files in the cache area and work area are rolled back to the specified commitID version content

Local warehouse and remote warehouse:

Forward:

git push origin [BranchName] pushes the content of the local warehouse branch to the remote branch

Reverse:

git reset --hard [commitID]、git push origin [BranchName] -f

Branch remote submission rollback, if the master is a protected branch, first perform the operation [gitlab] > [warehouse] > [branch], and then operate after canceling the protected branch

Branch operation:

git branch -a view all branches

git branch [BranchName] creates a new local branch from the current branch

git branch [BranchName] origin/[remotesbranch] creates a new local branch from a remote branch

git checkout [BranchName] switches the local branch, if there is no such branch locally and there is a remote branch with the same name, it will be automatically created to the local branch synchronously

git branch -d [BranchName] delete local branch

git push origin :[BranchName] deletes the remote branch

git push --set-upstream origin [remotesbranch] associates the local branch with the remote branch

git merge [BranchName] Merge a branch into the current branch, and ensure that the workspace files have been submitted to the local warehouse before merging

git remote View local branch remote library

git remote -v View local branch remote library address

git pull Pull code from remote

Stash operation:

git stash is used to store the workspace code when the master creates a new branch

git stash list View stash hidden storage list

git stash pop restores the workspace code and deletes stash content

Log operation:

git log View warehouse submission history (multi-line display)

git log --pretty=oneline View warehouse submission history (one line display)

git log --pretty=oneline --abbrev-commit View warehouse commit history (displayed as abbreviated commitID)

git log --graph view merge branch graph git

git reflog View execution command history

Diff operation:

git diff [FileName] Compare the difference between the workspace and the cache file

git diff HEAD -- [FileName] Compare the difference between the latest version of the workspace and the warehouse

Other operations:

git submodule update --init public directory (subproject) initialization command

git init creates a warehouse

git clone [GitHttps] Clone a remote branch

git status view status

git rm [FileName] removes a file

 git remote prune origin cleans up the local remote branch that the server has removed

git merge --squash origin/[BranchName] Commit multiple commit records of the branch into one record and merge it into master

Guess you like

Origin blog.csdn.net/zeping891103/article/details/108997429