0%
Git常用命令参考手册
基本git命令
目录
基础
配置
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| git config -l
git config --global --get user.name
git config --global user.name ${username}
git config --global --get user.email
git config --global user.email "[email protected]"
|
初始化本地仓库
文件状态
日志
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| git log
git log -2
git log -p -2
git log -S 你好
git shortlog -sn
git log --oneline
|
克隆
1 2 3 4 5 6 7 8 9 10 11
| git clone https://github.com/${username}/${git-repo}.git
git clone [email protected]:${username}/${git-repo}.git
git clone -b ${branch-name} https://github.com/${username}/${git-repo}.git
git clone --recursive ${username}@github.com/${username}/${git-repo}.git
|
分支操作
查看分支
1 2 3 4 5 6 7 8 9 10 11
| git branch --all
git branch
git remote -v
git branch -r
|
切换分支
1 2 3 4 5 6
| git checkout master git switch master
git checkout -
|
创建分支
1 2 3 4 5 6 7 8
| git branch dev
git checkout -b dev
git checkout -t origin/dev
|
删除分支
1 2 3 4 5 6
| git branch -d ${branchName}
git branch -d -r origin/${branchName} git push origin :${branchName}
|
重命名分支
1 2
| git branch -m ${branchName}
|
代码合并
1 2 3 4 5 6 7 8
|
git checkout dev
git merge feature
git merge feature dev
|
内容操作
暂存
1 2 3 4 5 6 7 8 9 10 11
| git add -A
git add ./README.md
git add .
git add 1.txt 2.txt ...
|
删除
git add 的反向操作
提交
1 2 3 4 5
| git commit -m "changes log"
git commit -v
|
推送
1 2 3 4 5 6 7 8 9 10 11
| git push -u origin master
git push origin ${localBranchName}:${remoteBranchName}
git push
git push -f
|
拉取、获取内容
1 2 3 4 5 6 7 8 9 10 11
| git fetch origin master
git pull
git pull origin master:master
git pull origin master
|
查看文件的改动
1 2 3 4 5 6 7 8 9 10 11 12
| git diff
git diff README.md
git diff ${commitId}
git log README.md git show ${commitId} README.md
|
回滚版本
1 2 3 4 5 6 7 8 9 10 11
| git reset --hard HEAD^
git reset --hard HEAD^^
git reset --hard '${commitId}'
git reflog
|
撤销
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| git checkout -- .
git checkout -- README.md
git reset HEAD ./README.md
git reset ${commitId}
git reset --hard ${commitId}
|
其他
标签
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
| git tag
git ls-remote --tags origin
git tag -l "v1.0.0*"
git tag -a v1.1.0 -m "标签描述"
git tag v1.1.0
git log git tag -a v1.1.0 ${commitId}
git push origin v1.1.0
git push origin --tags
git tag -d v1.1.0
git push origin --delete v1.1.0
git checkout v1.1.0
git show v1.1.0
|
密码配置
1 2 3 4 5 6 7 8
| git config --global credential.helper store
git credential-manager uninstall
git config --global credential.helper store
|
License
MIT