Following the last time, I took the time to sort out a relatively complete list of commonly used Git commands, and found a great map, very high-definition (1759*3162).
View, add, submit, delete, retrieve, reset modified files
git help
git show # Display the contents of a certain commit git show $id
git co –
git co . # Discard workspace modifications
git add
git add . # Submit all modified working files to the staging area
git rm
git rm
git reset
git reset – . # Restore from the staging area to the working file
git reset –hard # Restore the state of the last submission, that is, abandon all modifications since the last submission
git ci
git ci –amend # Modify the last commit record
git revert <$id> # Restore the status of a certain submission. The restore action itself also creates the submission object.
git revert HEAD #Restore the status of the last commit
View file diff
git diff
git diff <$id1> <$id2> # Compare the differences between two commits
git diff
git diff –staged # Compare the differences between the staging area and the repository
git diff –cached # Compare the differences between the staging area and the repository
git diff –stat # only compare statistics
View submission history
git log git log
git log -p
git log -p -2 # View the diff of the last two detailed modifications
git log –stat #View submission statistics
tig
You can use tig on Mac instead of diff and log, brew install tig
Git local branch management
View, switch, create and delete branches
git br -r # View remote branches
git br <new_branch> # Create a new branch
git br -v # View the last commit information of each branch
git br –merged # View branches that have been merged into the current branch
git br –no-merged # View branches that have not been merged into the current branch
git co
git co -b <new_branch> # Create a new branch and switch to it
git co -b <new_branch>
git co $id # Checkout a certain historical commit record, but there is no branch information. Switching to other branches will automatically delete it.
git co $id -b <new_branch> # Checkout a certain historical commit record and create a branch
git br -d
git br -D
Branch merging and rebase
git merge
git merge origin/master –no-ff # Do not Fast-Foward merge, so that merge submission can be generated
git rebase master
Git patch management (convenient for synchronization of development on multiple machines)
git diff > ../sync.patch # Generate patch
git apply ../sync.patch # Apply patch
git apply –check ../sync.patch #Test whether the patch is successful
Git staging management
git stash # temporary storage
git stash list # List all stash
git stash apply # Restore temporary contents
git stash drop # Delete the staging area
Git remote branch management
git pull # Grab all branch updates from the remote warehouse and merge them locally
git pull –no-ff # Grab all branch updates from the remote warehouse and merge them locally. Do not fast-forward the merge.
git fetch origin # Fetch remote warehouse updates
git merge origin/master # Merge the remote master branch into the local current branch
git co –track origin/branch # Track a remote branch and create a corresponding local branch
git co -b <local_branch> origin/<remote_branch> # Create a local branch based on the remote branch, the function is the same as above
git push # push all branches
git push origin master # Push the local master branch to the remote master branch
git push -u origin master # Push the local master branch to the remote (if there is no remote master branch, create it to initialize the remote warehouse)
git push origin <local_branch> # Create a remote branch, origin is the name of the remote warehouse
git push origin <local_branch>:<remote_branch> # Create a remote branch
git push origin :<remote_branch> #Delete the local branch first (git br -d
Git remote warehouse management
GitHub
git remote -v # View the remote server address and warehouse name
git remote show origin # View the remote server warehouse status
git remote add origin git@ github:robbin/robbin_site.git # Add remote warehouse address
git remote set-url origin git@ github.com:robbin/robbin_site.git # Set the remote warehouse address (used to modify the remote warehouse address) git remote rm
Create a remote warehouse
git clone –bare robbin_site robbin_site.git # Create a version-only repository using a versioned project
scp -r my_project.git git@ git.csdn.net:~ # Upload the pure warehouse to the server
mkdir robbin_site.git && cd robbin_site.git && git –bare init # Create a pure warehouse on the server
git remote add origin git@ github.com:robbin/robbin_site.git # Set the remote warehouse address
git push -u origin master # Client’s first submission
git push -u origin develop # Submit the local develop branch to the remote develop branch for the first time, and track
git remote set-head origin master # Set the HEAD of the remote warehouse to point to the master branch
You can also command to set up tracking remote libraries and local libraries
git branch –set-upstream master origin/master
git branch –set-upstream develop origin/develop
Warm reminder: If you want to enlarge the image, please open it in a new window.
