我错误地使用了git commit -a并在提交中添加了比我想要的更多的文件.还有另一个修改过的文件,我希望将其添加为此提交中包含的单独提交.我如何返回(不丢失对文件的修改)然后再单独提交它们.
我也把它推到了一个偏远的地方(虽然我知道自从我推动以来没有人拉过任何东西).
非常感谢!
警告,这将远程覆盖更改.如果有人取消了当前的提交并在其上工作,那么可能会发生不好的事情.
# Reset last commit, but keep changes staged
$ git reset --soft HEAD^1
# Unstage unwanted file(s) and recommit
$ git reset HEAD path/to/file
$ git commit
# Push the new commit with force to overwrite changes
$ git push origin -f
Run Code Online (Sandbox Code Playgroud)