This article summarizes the commands commonly used by git so that learners can consult the
Create
To copy a warehouse that you have created:
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:
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:
' message here '
Commit, and set the submission time to a previous date:
Git commit--Date="' date--date= ' N day ago '""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
List all Stash
git stash List
View a stash
git show [email protected]{0}
Delete a stash
git stash drop [email protected]{0}
Take the specified stash out.
git stash Apply [email protected]{1}
Take the last stash out and delete the corresponding values in the queue
Clear all Stash
Git stash Clea
Search
Find text content from all files in the current directory:
grep " Hello "
To search for text in a version:
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
List all the branches and their corresponding remote branches:
Git branch-vv
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<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>rm <resolved-File>
Merging of two branches, merging Other-branch into Main-branch
git checkout <other-branch><main-branch><main-branch>< Other-branch>
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>
Finally, a full picture showing the GIT process is included.
Reference: http://www.codeceo.com/article/git-command-guide.html
Concise Git Command Quick Check table