Git
Tutorial command cheat sheet
The foreword 0.
- In this paper,
99%
Summarized from Liao XuefengGit
The tutorial. - otherwise
1%
From personal experience.
1. Create a repository
The command | use |
---|---|
mkdir learngit cd learngit |
Create and go to an empty directory |
git init |
Initialize theGit warehouse |
Git add 1... |
Add files |
git add . |
Hold all changed files |
Git commit -m "Description" |
To submit documents |
2. Time travel
The command | use |
---|---|
git status |
View the current warehouse status |
Git diff filename |
View changes between the workspace and the staging area If the staging area is empty, view the changes made between the workspace and the repository’s last commit |
git log |
Display commit Log |
git log --pretty=oneline |
The commit log is displayed in a single line |
git reset --hard HEAD^ |
Return to the previous version |
git reset --hard HEAD^^ |
Return to the first two versions |
git reset --hard HEAD~100 |
Returns the first 100 versions |
Git reset --hard commit number |
Specifies to return to a version number |
git reflog |
Viewing Command History |
Git diff HEAD -- file name |
View the differences between the workspace and the latest version of the repository |
Git checkout -- file name |
Discard the workspace changes and go back to the last onegit add/commit When the state of the |
Git reset HEAD Name |
Roll back the staging changes to the workspace |
The rm file name Git rm/add filename Git commit -m "delete files" |
Delete files from the repository |
The rm file name Git checkout -- file name |
Recover an mistakenly deleted file from the text library |
3. Remote warehouse
The command | use |
---|---|
ssh-keygen -t rsa -C "youremail@example.com" |
createSSH The secret key to |
Git remote add origin git@github.com: your user name/repository name |
Associating remote libraries |
Git remote add origin https://github.com/ User name/repository name |
Associating remote libraries |
git push -u origin master |
First pushmaster Branch all contents and associate them with the remote librarymaster branch |
git push origin master |
pushmaster The latest modifications to the branch |
Git clone git@github.com: user name/repository name. Git |
Clone remote library to local (no.git All right) |
Git clone https://github.com/ Username/repository name. git |
Clone the remote library to the local |
4. Branch management
The command | use |
---|---|
git branch |
See the branch |
Git Branch Name |
Create a branch |
Git Checkout branch name |
Switch branch |
Git checkout -b Branch name |
Create and switch branches |
Git merge branch name |
Merge the branch name into the current branch |
Git branch -d Specifies the name of a branch |
Delete the branch |
git log --graph --pretty=oneline -abbrev-commit |
View branch merges |
Git merge -- no-f-m "Commit note" branch name |
Merge branches in non-fast forward mode |
git stash |
Storage area |
git stash list |
View the list of workspace stores |
git stash apply git stash drop |
Restore work area Delete stored content |
Git stash apply stash@{number} Git stash drop Stash @{number} |
Restores the workspace from the specified store and deletes the stored content |
git stash pop |
Restore the stored content and delete it simultaneously |
Git branch -d Specifies the name of a branch |
Deletes unmerged branches |
git remote |
View information about remote libraries |
git remote -v |
View details about remote libraries |
Git push Origin branch name |
Push the branch |
Git checkout -b branch name origin/ branch name |
Create a branch locally |
Git branch -- set-ups-to =origin |
Specifies the link between the local branch and the remote branch |
git pull |
Grab the latest remote commit |
git rebase |
Change the base, put the local notpush The forked submit history is sorted into straight lines |
5. Label management
The command | use |
---|---|
Git Tag Name of a tag |
Tag the latest submission for the current branch |
Git Tag Tag name commit number |
Labels the specified submission number |
git tag |
View all tag names |
Git show tag name |
Viewing Label Details |
Git tag -a -m "git tag description" |
Create a label with instructions |
Git push origin tag name |
Push local Labels |
git push origin --tags |
Push all unpushed local labels |
Git tag -d Specifies the tag name |
Deleting a Local Label |
Git tag -d Specifies the tag name Git push Origin :refs/tags/ tags |
Deleting a Remote Label |
6. Use code clouds
The command | use |
---|---|
git remote rm origin |
deleteorigin The remote repository |
Git remote add github git@github.com: user name/repository name |
addGitHub The remote repository |
Git remote add gitee git@gitee.com: user name/repository name. git |
addGitee The remote repository |
git push github master |
Pushed to theGitHub |
git push gitee master |
Pushed to theGitee |
7. The customGit
The command | use |
---|---|
git config --global color.ui true |
letGit According to the color |
Git add -f File name |
Forcing file addition |
Git check-ignore -v File name |
View the line on which the file is.ignore ignore |
git config --global alias.st status |
withst Instead ofstatus |
git config --global alias.co checkout |
withco Instead ofcheckout |
git config --global alias.ci commit |
withci Instead ofcommit |
git config --global alias.br branch |
withbr Instead ofbranch |
git config --global alias.unstage 'reset HEAD' |
Undo temporary area modificationGit unstage File name Can be |
git config --global alias.last 'log -1' |
withgit last Displays the last commit |
git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit" |
withgit lg Display commit Log |
Under the current warehouse.git/config file |
The configuration file for the current repository |
In the user’s home directory.gitconfig file |
Configuration file of the current user |
Commonly used 8.Git
Command quick lookup table
2018.08.16 First revision 2019.01.17 Second revision 2019.03.06 Third revision: Added quick reference table of common Git commands