基础操作¶
# 提交代码
git add .
git commit -m ""
# 拉取、推送
git pull
git push
# 提交到远端指定分支
git push origin HEAD:refs/for/master # 将本地HEAD 提交到 /refs/for (gerrit 评审)
_撤回、回滚
# 撤回暂存(默认 --mixed)
git reset
# 撤回提交
git reset --soft HEAD~1 # 撤回提交,并将更改保留在暂存区
git reset --mixed HEAD~1 # 撤回提交,并将更改从暂存区移除,但保留在工作目录中
git reset --hard HEAD~1 # 撤回最新提交,并丢弃所有更改
git push origin master -f
# 回滚 不会改变历史记录,而是通过新的提交来撤销之前的更改
git revert <commit-hash>
# 修改上一次提交内容
git commit --amend
git commit --amend --no-edit # 重新生成提交Hash
_分支
# 查看、删除、切换、创建并切换分支
git branch
git branch -D branch_name
git checkout branch_name
git checkout -b branch_name
# 压缩提交
git checkout target-branch # 切换到目标分支
git merge --squash source-branch # 合并源分支的所有更改为一个未提交的变更集
git commit --no-edit # 提交这些变更
提交规范