Home  >  Article  >  Backend Development  >  Git command cheat sheet Chinese version

Git command cheat sheet Chinese version

伊谢尔伦
伊谢尔伦Original
2016-11-30 10:04:02972browse

Create

Copy an already created repository:

$ git clone ssh://user@domain.com/repo.git

Create a new local repository:

$ git init

Local modification

Show modified files under the working path:

$ git status

Show the differences from the last submitted version of the file:

$ git diff

Add all current changes to the next commit:

$ git add

Add changes to a file to the next commit:

$ git add -p <file>

Submit all local changes:

$ git commit -a

Submit previously marked changes :

$ git commit

Additional message commit:

$ git commit -m &#39;message here&#39;

Commit and set the commit time to a previous date:

git commit --date="`date --date=&#39;n day ago&#39;`" -am "Commit Message"

Modify the last commit
Please do not modify the published commit record!

$ git commit --amend

Put the commit time in the current branch that is not Commit changes moved to other branches

git stash
git checkout branch2
git stash pop

Search

Find text content from all files in the current directory:

$ git grep "Hello"

Search for text in a certain version:

$ git grep "Hello" v2.5

Commit history

Start with the latest commit, display all Submission record (show hash, author information, title and time of submission):

$ git log

Show all submissions (only show hash and message of submission):

$ git log --oneline

Show all submissions of a certain user:

$ git log --author="username"

Show a certain file All modifications:

$ git log -p <file>

Who, when, and what modified the file:

$ git blame <file>

Branches and tags

List all branches:

$ git branch

Switch branches:

$ git checkout <branch>

Create and switch to a 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>

Updates and releases

List Currently configured remote end:

$ git remote -v

Display remote end information:

$ git remote show <remote>

Add a new remote end:

$ git remote add <remote> <url>

Download the remote end version, but not merge it into HEAD:

$ git fetch <remote>

Download the remote end version and automatically merge it with HEAD Version merge:

$ git remote pull <remote> <url>

Merge remote version into local version:

$ git pull origin master

Publish local version to remote:

$ 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 With Reset

Merge branch into current HEAD:

$ git merge <branch>

Reset current HEAD version into branch:
Do not reset published commits!

$ git rebase <branch>

Exit Reset:

$ git rebase --abort

Continue after resolving conflicts Reset:

$ git rebase --continue

Use the configured merge tool to resolve conflicts:

$ git mergetool

After manually resolving conflicts in the editor, mark the file as resolved conflict

$ git add <resolved-file>
$ git rm <resolved-file>

Undo

Discard all modifications in the working directory:

$ git reset --hard HEAD

Remove all files from the cache (i.e. undo the last git add):

$ git reset HEAD

Discard all local modifications to a file:

$ git checkout HEAD <file>

Reset a commit (by creating a distinct new commit)

$ git revert <commit>

Change HEAD Reset to the specified version and discard all modifications after that version:

$ git reset --hard <commit>

将HEAD重置到上一次提交的版本,并将之后的修改标记为未添加到缓存区的修改:

$ git reset <commit>

将HEAD重置到上一次提交的版本,并保留未提交的本地修改:

$ git reset --keep <commit>


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn