----------------Camp David Education finishing--------------------
Index
- Create
- Local modifications
- Search
- Submit History
- Branches and labels
- Update and release
- Merging and resetting
- Revoke
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 to some previous date:
git commit --date="`date --date=‘n day ago‘`" -am "Commit Message"
Modify Last Commit
Don ' t amend published commits!
$ 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 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 operations on the current remote end:
$ 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)orgit 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:
Don ' t rebase published commit!
$ 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, the tag file is已解决冲突
$ 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>
Reset the head to the last committed version and discard any subsequent modifications:
$ 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>
Git Cheat Sheet Chinese