clone仓库:
git clone <仓库地址>
递归clone项目:
git clone --recurse-submodules <repo-address>
从当分支上创建新分支:
git checkout -b <new-branch>
切换分支:
git checkout -b <other-branch>
从指定远程仓库中指定分支上创建新的分支:
git checkout -b <new-branch> <remote-repo>/<branch-name>
查看分支:
git branch # 默认查看本地分支
-d
查看stash区内容:
git stash list
将所有更改加入到stash:
git stash
弹出stash栈顶:
git stash pop
清空stash:
git clear
将指定文件加入到暂存区:
git add <filename>
将当前目录所有文件加入到暂存区:
git add .
显式指定作者名字邮箱:
git commit --author="" -c <commit-sha>
对commit签名:
git commit -S -m <commit-message>
撤回未push的commit:
git reset --soft HEAD^ # 撤回一次
git reset --soft HAED2 # 撤回两次
添加新的远程仓库:
git remote add <local-remote-repo-name> <repo-address>
抓取新分支:
git fetch <branch-name>
push的同时设置上游分支:
git push -u <local-repo-name> <branch-name>
git push -u
会将本地分支与远程分支关联,这样以后就可以直接用git push
和git pull
如果想单独撤销某个commit修改,可以使用git revert
git revert <commit-hash>
同样的,如果不想立马提交,想要修改commit log,添加选项-n
git revert -n <commit-hash>
1. 开始二分:
git bisect start
2. 标记初始坏commit:
git bisect bad
3. 标记好的commit:
git bisect good <commit-hash>
之后git会自动切换到中间commit
4. 开始查找:
如果是好的commit,标记:
git bisect good
否则:
git bisect bad
5. 结束查找:
最后git会给出错误的commit信息
执行命令结束查找
git bisect reset
如果想要把最近提交的commit打包成patch方便别人使用,可以使用该命令:
如果想把远程仓库的某个commit应用到当前分支,可以使用以下命令:
git cherry-pick <commit-hash>
在新的commit中自动添加签名(Signed-off-by),这是一个git用来标识提交作者并确认对提交内容的合法性的一种方式
git cherry-pick -s <commit-hash>
如果不想立马提交,想要修改commit log,添加选项-n
:
git cherry-pick -n <commit-hash>
想知道哪些tag包含了某个commit
git tag --contain <commit-sha>
查看一个文件提交时间线:
git log --oneline -- <文件路径>
参考资料:https://docs.github.com/zh/authentication/managing-commit-signature-verification/about-commit-signature-verification#gpg-commit-signature-verification