我刚刚读过修改git过去提交中的单个文件,但不幸的是,接受的解决方案"重新排序"了提交,这不是我想要的.所以这是我的问题:
我偶尔会在处理(无关)功能时发现我的代码中存在错误.然后快速git blame揭示该错误已经被引入了一些提交之前(我提交了很多,所以通常它不是引入该错误的最新提交).此时,我通常这样做:
git stash # temporarily put my work aside
git rebase -i <bad_commit>~1 # rebase one step before the bad commit
# mark broken commit for editing
vim <affected_sources> # fix the bug
git add <affected_sources> # stage fixes
git commit -C <bad_commit> # commit fixes using same log message as before
git rebase --continue # base all later changes onto this
Run Code Online (Sandbox Code Playgroud)
然而,这种情况经常发生,上述序列变得烦人.特别是'互动式底板'很无聊.上面的序列是否有任何快捷方式,这可以让我修改过去的任意提交和分阶段的更改?我完全清楚这会改变历史,但我经常犯错误,所以我真的很喜欢这样的事情.
vim <affected_sources> # fix bug
git add -p <affected_sources> # Mark …Run Code Online (Sandbox Code Playgroud)