Home > Backend Development > PHP Tutorial > Git command cheat sheet Chinese version

Git command cheat sheet Chinese version

伊谢尔伦
Release: 2023-03-01 11:06:02
Original
1059 people have browsed it

Create

Copy an already created repository:

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

Create a new local repository:

$ git init
Copy after login

Local modification

Show modified files under the working path:

$ git status
Copy after login

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

$ git diff
Copy after login

Add all current changes to the next commit:

$ git add
Copy after login

Add changes to a file to the next commit:

$ git add -p <file>
Copy after login

Submit all local changes:

$ git commit -a
Copy after login

Submit previously marked changes :

$ git commit
Copy after login

Additional message commit:

$ git commit -m &#39;message here&#39;
Copy after login

Commit and set the commit time to a previous date:

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

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

$ git commit --amend
Copy after login

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
Copy after login

Search

Find text content from all files in the current directory:

$ git grep "Hello"
Copy after login

Search for text in a certain version:

$ git grep "Hello" v2.5
Copy after login

Commit history

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

$ git log
Copy after login

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

$ git log --oneline
Copy after login

Show all submissions of a certain user:

$ git log --author="username"
Copy after login

Show a certain file All modifications:

$ git log -p <file>
Copy after login

Who, when, and what modified the file:

$ git blame <file>
Copy after login

Branches and tags

List all branches:

$ git branch
Copy after login

Switch branches:

$ git checkout <branch>
Copy after login

Create and switch to a new branch:

$ git checkout -b <branch>
Copy after login

Create a new branch based on the current branch:

$ git branch <new-branch>
Copy after login

Create a new traceable branch based on the remote branch:

$ git branch --track <new-branch> <remote-branch>
Copy after login

Delete local branch:

$ git branch -d <branch>
Copy after login

Tag the current version:

$ git tag <tag-name>
Copy after login

Updates and releases

List Currently configured remote end:

$ git remote -v
Copy after login

Display remote end information:

$ git remote show <remote>
Copy after login

Add a new remote end:

$ git remote add <remote> <url>
Copy after login

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

$ git fetch <remote>
Copy after login

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

$ git remote pull <remote> <url>
Copy after login

Merge remote version into local version:

$ git pull origin master
Copy after login

Publish local version to remote:

$ git push remote <remote> <branch>
Copy after login

Delete remote branch:

$ git push <remote> :<branch> (since Git v1.5.0)
Copy after login

or

git push <remote> --delete <branch> (since Git v1.7.0)
Copy after login

Release tag:

$ git push --tags
Copy after login

Merge With Reset

Merge branch into current HEAD:

$ git merge <branch>
Copy after login

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

$ git rebase <branch>
Copy after login

Exit Reset:

$ git rebase --abort
Copy after login

Continue after resolving conflicts Reset:

$ git rebase --continue
Copy after login

Use the configured merge tool to resolve conflicts:

$ git mergetool
Copy after login

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

$ git add <resolved-file>
$ git rm <resolved-file>
Copy after login

Undo

Discard all modifications in the working directory:

$ git reset --hard HEAD
Copy after login

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

$ git reset HEAD
Copy after login

Discard all local modifications to a file:

$ git checkout HEAD <file>
Copy after login

Reset a commit (by creating a distinct new commit)

$ git revert <commit>
Copy after login

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

$ git reset --hard <commit>
Copy after login

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

$ git reset <commit>
Copy after login

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

$ git reset --keep <commit>
Copy after login


Related labels:
git
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template