Git忘记将文件更改添加到尚未推送的提交(不是最后一个)
我想将文件更改添加到尚未推式提交(不是最后一个)中 假设我有以下场景:Git忘记将文件更改添加到尚未推送的提交(不是最后一个),git,Git,我想将文件更改添加到尚未推式提交(不是最后一个)中 假设我有以下场景: git init touch test.txt // do some changes to the text file git commit -a -m "First change" # if I now change something I can add it to the previous commit with: git add test.txt git commit --amend -C HEAD # mor
git init
touch test.txt
// do some changes to the text file
git commit -a -m "First change"
# if I now change something I can add it to the previous commit with:
git add test.txt
git commit --amend -C HEAD
# more changes to test.txt
git commit -a -m "Second change"
# more changes to test.txt
git commit -a -m "Third change"
# one more change
# how can I add the change to my second commit (second change)?
我希望问题是清楚的。如果没有,请告诉我。我尝试了git提交--amend-C HEAD~2,但那一个在我真正的git项目中引起了一些奇怪的麻烦。你可以使用git-rebase。我建议阅读
git-help-rebase
,尤其是INTERACTIVE_MODE
部分,因为在执行rebase时小心是明智的
假设上次提交是“第三次更改”,您可以:
git-rebase-i头~2
git添加
其他文件,并在准备就绪后执行git提交--修改
,这将加载一个编辑器,您可以在其中编辑第二个更改的提交日志消息git-rebase——继续。这将在修改后的第二次更改上重播第三次更改
您可以使用
git-rebase
。我建议阅读git-help-rebase
,尤其是INTERACTIVE_MODE
部分,因为在执行rebase时小心是明智的
假设上次提交是“第三次更改”,您可以:
git-rebase-i头~2
git添加
其他文件,并在准备就绪后执行git提交--修改
,这将加载一个编辑器,您可以在其中编辑第二个更改的提交日志消息git-rebase——继续。这将在修改后的第二次更改上重播第三次更改
edit xxxxxxx Second change
pick xxxxxxx Third change