Simple Git command quick query table (Chinese Version)
Create
Copy A created warehouse:
$ git clone ssh://[email protected]/repo.git
Create a new local repository:
$ git init
Local Modification
Display the modified files in the working path:
$ git status
Different from the last submitted version file:
$ git diff
Add all current modifications to the next submission:
$ git add
Add modifications to a file to the next submission:
$ git add -p <file>
Submit all local modifications:
$ git commit -a
Submitted previously marked changes:
$ git commit
Additional message submission:
$ git commit -m 'message here'
Submit and set the submission time to a previous date:
git commit --date="`date --date='n day ago'`"-am "Commit Message"
Last modification submitted
Do not modify published submission records!
$ git commit --amend
Move uncommitted changes in the current branch to another branch
git stash
git checkout branch2
git stash pop
Search
Search for text from all files in the current directory:
$ git grep "Hello"
Search for text in a specific version:
$ git grep "Hello" v2.5
Submission history
All submission records (hash, author information, submission title, and time) are displayed starting from the latest submission ):
$ git log
Show all submissions (only the submitted hash and message are displayed ):
$ git log --oneline
Display All submissions of a user:
$ git log --author="username"
Display All modifications to a file:
$ git log -p <file>
Who, at what time, modified the content of the file:
$ git blame <file>
Branch and label
List all branches:
$ git branch
Switch Branch:
$ git checkout <branch>
Create and switch to the new branch:
$ git checkout -b <branch>
Create a new branch based on the current Branch:
$ git branch <new-branch>
Create a new traceable branch based on the remote Branch:
$ git branch --track <new-branch><remote-branch>
Delete local branch:
$ git branch -d <branch>
Tag the current version:
$ git tag <tag-name>
Update and release
List the remote end of the current configuration:
$ git remote -v
Display remote terminal information:
$ git remote show <remote>
Add a new remote terminal:
$ git remote add <remote><url>
Download the remote version but not merge it into the HEAD:
$ git fetch <remote>
Download the remote version and automatically merge it with the HEAD version:
$ git remote pull <remote><url>
Merge the remote version into the local version:
$ git pull origin master
Publish the local version to the remote end:
$ git push remote <remote><branch>
Delete remote Branch:
$ git push <remote>:<branch>(since Git v1.5.0)
Or
git push <remote>--delete<branch>(since Git v1.7.0)
Release Tag:
$ git push --tags
Merge and reset
Merge the branches into the current HEAD:
$ git merge <branch>
Reset the current HEAD version to the Branch:
Do not reset published submissions!
$ git rebase <branch>
Exit Reset:
$ git rebase --abort
Continue resetting after resolving the conflict:
$ git rebase --continue
Use the configured merge tool to resolve the conflict:
$ git mergetool
After manually resolving the conflict in the editor, mark the fileConflict resolved
$ git add <resolved-file>
$ git rm <resolved-file>
Undo
Discard all modifications in the working directory:
$ git reset --hard HEAD
Remove all files in the cache (I. e. Undo last timegit add
):
$ git reset HEAD
Discard all local modifications to an object:
$ git checkout HEAD <file>
Reset a Commit (by creating a completely different new commit)
$ git revert <commit>
Reset the HEAD to the specified version and discard all modifications after the version:
$ git reset --hard <commit>
Reset the HEAD to the version submitted last time, and mark the subsequent modifications as those not added to the cache:
$ git reset <commit>
Reset the HEAD to the last submitted version, and retain uncommitted local modifications:
$ git reset --keep <commit>
GitHub Tutorials:
GitHub tutorials
Git tag management details
Git branch management
Git remote repository details
Git local Repository (Repository) Details
Git server setup and Client installation
Git Overview
Share practical GitHub tutorials
Git details: click here
Git: click here
This article permanently updates the link address: