Create
To copy a warehouse that you have created:
$ git clone ssh://[email protected]/repo.git
To create a new local repository:
$ git init
Local modifications
Show modified files under work path:
$ git status
Display differs from the last commit version file:
$ git diff
Add all current changes to the next commit:
$ git add
To add changes to a file in the next commit:
$ git add-p <file>
Commit all local modifications:
$ git commit-a
Changes that were marked before committing:
$ git commit
Additional Message submissions:
$ git commit-m ' message here '
Commit, and set the submission time to a previous date:
git commit--date= "' Date--date= ' N day ago '"-am "commit Message"
Modify Last Commit
Do not modify a published submission record!
$ git commit--amend
Move uncommitted changes in the current branch to another branch
git stashgit checkout branch2git stash Pop
Search
Find text content from all files in the current directory:
$ git grep "Hello"
To search for text in a version:
$ git grep "Hello" v2.5
Submit History
From the latest submission, show all commit records (display hash, author information, submitted title and time):
$ git log
Show all commits (only the submitted hash and message are shown):
$ git log--oneline
Show all submissions for a user:
$ git log--author= "username"
Show all changes to a file:
$ git log-p <file>
Who, at what time, modified what content of the file:
$ git blame <file>
Branches and labels
List all the branches:
$ git Branch
To switch branches:
$ git checkout <branch>
To create and switch to a new branch:
$ git checkout-b <branch>
To create a new branch based on the current branch:
$ git Branch <new-branch>
Create a new traceable branch based on a remote branch:
$ git branch--track <new-branch> <remote-branch>
To delete a local branch:
$ git branch-d <branch>
To label the current version:
$ git tag <tag-name>
Update and release
List the remote side of the current configuration:
$ git remote-v
Displays information from the remote side:
$ git remote show <remote>
To add a new remote end:
$ git remote add <remote> <url>
Download the remote end version, but do not merge into the head:
$ git fetch <remote>
Download the remote end version and automatically merge with the head version:
$ git remote pull <remote> <url>
To merge the remote end version into the local version:
$ Git pull Origin Master
To publish a local version to the remote side:
$ git push remote <remote> <branch>
To delete a remote-side branch:
$ git push <remote>:<branch> (since git v1.5.0) or git push <remote>--delete <branch> (since git v1 .7.0)
Publish Tags:
$ git push--tags
Merging and resetting
To merge the branches into the current head:
$ git Merge <branch>
Resets the current head version to the branch:
Do not reset a published submission!
$ git rebase <branch>
To exit the Reset:
$ git rebase--abort
Continue resetting after resolving conflicts:
$ git rebase--continue
Resolve conflicts using the configured merge tool:
$ git Mergetool
After manually resolving conflicts in the editor, mark files as resolved conflicts
$ git Add <resolved-file>
$ git rm <resolved-file>
Revoke
Discard all changes under the working directory:
$ git reset--hard HEAD
Remove all files from the cache (i.e. undo last git Add):
$ git reset HEAD
Discard all local modifications to a file:
$ git checkout HEAD <file>
Reset a commit (by creating a completely different new submission)
$ git revert <commit>
Resets the head to the specified version and discards all modifications after that version:
$ git reset--hard <commit>
Resets the head to the last committed version and marks the subsequent modifications as not added to the buffer:
$ git reset <commit>
Reset the head to the last committed version and leave uncommitted local modifications:
$ git reset--keep <commit>
Concise Git Command Quick Check table