You can use git rebase .
(您可以使用git rebase 。)
For example, if you want to modify commit bbc643cd
, run (例如,如果要修改commit bbc643cd
,请运行)
$ git rebase --interactive 'bbc643cd^'
Please note the caret ^
at the end of the command, because you need actually to rebase back to the commit before the one you wish to modify .
(请注意命令末尾的插入符^
,因为实际上您需要在要修改的提交之前将基准变回提交 。)
In the default editor, modify pick
to edit
in the line mentioning 'bbc643cd'.
(在默认编辑器中,修改pick
以在提到“ bbc643cd”的行中进行edit
。)
Save the file and exit: git will interpret and automatically execute the commands in the file.
(保存文件并退出:git将解释并自动执行文件中的命令。)
You will find yourself in the previous situation in which you just had created commit bbc643cd
. (您会发现自己处在之前创建commit bbc643cd
的先前情况中。)
At this point, bbc643cd
is your last commit and you can easily amend it : make your changes and then commit them with the command:
(此时, bbc643cd
是您的最后一次提交,您可以轻松地对其进行修改 :进行更改,然后使用以下命令提交它们:)
$ git commit --all --amend --no-edit
After that, type:
(之后,输入:)
$ git rebase --continue
to return back to the previous HEAD commit.
(返回上一个HEAD提交。)
WARNING : Note that this will change the SHA-1 of that commit as well as all children -- in other words, this rewrites the history from that point forward.
(警告 :请注意,这将更改该提交以及所有子项的SHA-1-换句话说,这将从该点开始重写历史记录。)
You can break repos doing this if you push using the command git push --force
(如果使用命令git push --force
推送,则可以中断存储库)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…