git rebase在提交时停止,查看和编辑每个

GDY*_*ell 12 git

我注意到当我进行rebase并发生合并冲突时,它会对当前提交进行分阶段更改,因此很容易找到提交中的内容并进行更改,但之后你也可以执行'git rebase --continue '并且它将使用与之前相同的提交消息来应用更改.

有没有办法强制这种情况发生在特定的提交或所有提交中,所以我可以轻松地修改和编辑我之前所做的更改,以便使用我已经重新定义的更改?看起来这比仅仅在所有提交上设置编辑然后执行'git reset --soft HEAD~'更容易,这样更改是可见的,我可以检查它们对新的HEAD,编辑和必须做'git commit -m'消息"'.

我的用例是我正在使用的存储库已经对其文件结构进行了大量重构,并且git无法进行适当的更改,但是说合并成功了.

谢谢!

hsp*_*her 9

我认为您正在寻找的是交互式变基和重写git历史.它会让你压缩提交以及更改提交消息.

git rebase -i branch # <branch> should be the parent branch i.e. develop/master
Run Code Online (Sandbox Code Playgroud)

重写git历史

# for instance
>>> git rebase -i branch
pick 8705209 first
edit 7979797 second # Use edit wherever you want to view and edit commit
squash 9793757 third # Use squash to squash commits into the previous one.
Run Code Online (Sandbox Code Playgroud)

  • 将每个提交更改为"编辑"而不是"选择"是关键.Rebase将在每次提交时停止并允许您进行更改. (5认同)

gue*_*est 5

强制针对特定提交发生这种情况

使用 启动交互式变基git rebase -i HEAD~~~

这将打开一个包含提交列表的编辑器:

pick 1234567 fix stuff
pick 789abcd new features
pick 0102030 break everything
Run Code Online (Sandbox Code Playgroud)

将 更改pickedit您要编辑的一个(或多个)提交。保存并退出编辑器。

然后,git 会将你一一带回这些提交,你可以编辑它们。我认为您缺少的是,此时您可以使用 . 查看已上演的差异git diff --cached

编辑完每一项后,请使用git rebase --continue继续。


kan*_*kan 4

git commit --amend之前就做吧git rebase --continue

或者 - 使用git-cherry-pick --no-commit commit1..commitN.