如何 git rebase -i edit 并查看过去的提交更改

Ela*_*ron 7 git commit rebase

通常我会编辑旧的提交,并git rebase -i HEAD~<number of commits I added>添加edit我想要编辑的提交,进行更改,添加文件和git rebase --continue.

有没有办法使用 rebase 编辑提交但查看过去的提交更改?找到我想要修复的地方会更容易,VScode 会帮我标记这些行。

例如:假设我已经提交了commitA, commitB, commitC(HEAD at commitC)。现在我想编辑commitA. 我已经git rebase -i HEAD~3提交edit了 commitA。现在我正处于变基过程中,但我希望commitA 更改显示为更改,这种情况使我在commitA更改已经提交时编写修复程序。

如果有一种替代方法可以修复过去的提交并更改该提交,staged那就太好了。

提前致谢!

Ela*_*ron 6

好吧,似乎比我想象的要容易!只需按照以下步骤操作:假设我想编辑 5 个提交:

  1. git rebase -i HEAD~5
  2. 将 pick to edit 更改为要编辑的提交。
  3. 如果您想查看当前提交更改类型,那么您的交互式变基将会启动,git reset HEAD~1因为提交已经存在,我们只是重置它。
  4. 做出你的改变。
  5. git add <files of your change and past commit files>或者只是git add -u添加所有跟踪的文件。
  6. git commit
  7. git rebase --continue

快乐 gitting :)

  • 我自己发现了: `git commit --reuse-message=ORIG_HEAD` 将使用 `git reset HEAD~1` 之前提交的提交消息。如果您需要更改该消息中的某些内容,请在之后执行“git commit --amend”。 (3认同)