Git 指南
# 工作常用
# 配置
| |
| git config --global user.name xxx |
| git config --global user.email yyy |
| |
| git config --global --list |
| |
| |
| git config --global core.editor vim |
| |
| git config --global alias.<alias-name> <git-command> |
| |
| git config --system core.editor <editor> |
| |
| git config --global --edit |
| |
| |
| git init --bare <directory> |
# 查看
| |
| git status |
| |
| git show 提交记录id |
| |
| git diff --staged |
| |
| git diff <commit> <commit> |
| |
| git diff <branch>..<branch> |
| |
| git branch -r |
| git checkout XXX |
| git remote add origin <server> |
# 还原
| |
| git restore filename |
| |
| git restore --staged filename |
| |
| git restore --source=HEAD-1 filename |
| |
| git restore dir/ |
| |
| |
| git reset --hard df66027f00c(版本号) |
# 分支
| |
| git branch |
| |
| |
| git branch branch-name |
| git branch -d branch-name |
| |
| git branch -D branch-name |
| |
| |
| git checkout branch-name |
| git checkout -b branch-name |
| |
| |
| git merge branch-name |
# 提交
| |
| git add |
| |
| git commit -s |
| |
| git commit --amend |
| |
| |
| git commit --amend --no-edit |
# 暂存
| |
| git stash |
| git stash list |
| git stash clear |
| git stash apply |
| |
| git stash pop |
# 远程相关
| |
| git pull --rebase |
| |
| git fetch -p |
| |
| |
| git push origin branch-name |
| git push ssh://账号@项目路径 HEAD:分支 |
| |
| |
| git cherry-pick <commit>.. |
| |
| git cherry-pick --continue |
--rebase
是将远程代码拉取到本地,并且将自己的修改放置在最前面。 pull 对比 pull --rebase
# 原理相关
# 文件的状态:
- untracked 未跟踪
- unmodified 未修改
- modified 已修改
- staged 已暂存
- committed 已提交
# Git 提交规范
- feat:新功能
- fix:修补 bug
- docs:文档
- style : 格式
- refactor:重构
- test:增加测试
- chore:构建过程或辅助工具的变动
# Gerrit
使用 commit --amend 追加前面提交的时候,gerrit 通过 changeId 来判断,从而使得 push 的时候可以追加到之前的提交,只是在远程加了 patchsetN