git 修改某个commit 内容

某个commit 中的修改代码遗漏, 如何修改指定commit,如图
image.png

想 修改refactor: api/dmEditor/source/character/static2d
提交内容,不产生新的commit.
好像使用git rebase 后无法执行提交,好像并未找到BCompare

$ git rebase -i bd9a0d8c67ebc9be512bb175ee8713b9179e2216
hint: Waiting for your editor to close the file... error: cannot spawn BCompare: No such file or directory
error: unable to start editor 'BCompare'
git commit --amend
hint: Waiting for your editor to close the file... error: cannot spawn BCompare: No such file or directory
error: unable to start editor 'BCompare'
Please supply the message using either -m or -F option.
阅读 4.8k
2 个回答

这种情况,如果还没有推送到远端的话,回退重新提交可以,检出到你要修改的前一个点检出新分支,然后遴选过来你要修改的点不 commit, 然后把你要追加修改的内容加进去,然后 commit, 再把后面的其他点全部遴选过来. 这种情况下你是用 rebase 是要干嘛啊?不太懂?

如果已经推到远端了,本地操作完成之后,需要远端给你覆写这个分支的权限,让你把你本地的变更强推上去.

这里报 「BCompare 错误」 是因为 git 指定的编辑器是 「BCompare」 而你没有这个编辑器。
解决方法是指定编辑器:

$ git config --global core.editor vim

我这里是指定为 vim, 你可以指定成自己熟悉的编辑器。再来进行 rebase。
需要注意的 rebase 会将你修改那一条 commit 的之后的 commit 全部重新提交一边。所以如果已经将代码推送到远端,我的建议的不修改 commit 。
另外,如果搞坏了,可以使用 git reflog 来退回之前的代码。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进