本文是Git常用命令的参考手册。
git常用命令
以下是一些常用的 Git 命令,按照用途分类整理:
配置设置
1 2 3 4 5 6 7
| git config --list --show-origin git config --global user.name "xxx" git config --global user.email xxx@xxx.com git config --global alias.co checkout git config --global alias.ci commit git config --global alias.st status git config --global alias.last 'log -1 HEAD'
|
基础操作
1 2 3 4 5 6
| git init git clone <repository-url>
git help <verb> git <verb> --help man git-<verb>
|
版本控制
1 2 3 4 5 6 7
| git status git add <file> git add . git commit -m "提交信息" git log git log --oneline git reflog
|
分支管理
1 2 3 4 5 6 7 8 9 10
| git branch git branch <branch-name> git checkout <branch-name> git checkout -b <branch-name> git checkout -t origin/branch_name git merge <branch-name> git branch -d <branch-name> git branch -D <branch-name> git branch --merged git branch --no-merged
|
远程操作
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| git remote -v git clone <repository-url> git remote add origin <repository-url>
git push -u (第一次需要-u以后不需要) git push origin <branch-name> git push origin serverfix:awesomebranch git push -d origin branch_name
git fetch <remote> git pull git pull origin branch_name
git remote remove
|
标签管理
1 2 3 4 5 6 7
| git tag git tag -a v1.4 -m "my version 1.4" git tag -d <tagname> git push origin <tagname> git push origin --tags git push origin --delete <tagname> git push <remote> :refs/tags/<tagname>
|
恢复与撤销
1 2 3 4 5 6 7 8
| git rm <file> git rm --cached <file> git checkout -- <file> 或 git restore XX git reset HEAD <file> git reset --hard <commit-id> git reset --hard HEAD^ 或 git reset --hard HEAD~ git reset --hard HEAD^^ git reset --hard HEAD~100
|
高级操作
1 2 3 4 5 6 7 8 9 10 11 12 13
| git diff xx git diff --staged git difftool --tool-help
git push --set-upstream origin <branch-name> git push --set-upstream origin branch_name git branch --set-upstream-to=origin/branch_name1 branch_name2
git stash git stash apply git stash drop git stash pop git stash list
|