在gerrit下git commit --amend和git rebase之间的区别

时间:2013-01-09 09:19:02

标签: git gerrit

我想更改上次提交内容。 我可以做当地的改变。 然后执行

git commit --amend

我也可以做以下事情:

git rebase -i HEAD~

选择要编辑的提交。 做地方改变 然后执行:

git rebase --continue
  1. 这种情况下这两个命令有区别吗?
  2. 在Gerrit的背景下,当涉及到gerrit的CHANGE-ID时?

2 个答案:

答案 0 :(得分:4)

没有。它们都使用先前的提交作为模板来生成新的提交。 Gerrit change-id只是由提交注释中的行跟踪,因此如果您不修改或删除该行,Gerrit仍然可以在引用该更改时跟踪此新提交。

答案 1 :(得分:1)

假设您有3个提交A-> B-> C,并且您更改了包含在提交A中的文件,那么,您应该在顶部进行提交A

git stash /* to save your changes */

git rebase -i HEAD~3
move commit A at the bottom of commits B&C
save&exit

如果你做

git log

你将有这个序列B-> C-> A,你做

git add /*your changed file*/
git commit --amend

现在你必须返回提交A回到不改变gerrit依赖列表

git rebase -i HEAD~3
move commit A at the top of commit B&C
save&exit

现在,如果你推动gerrit,你将拥有相同的旧订单

相关问题