它是这样的:
我修改了文件 A 和 B
我只打算提交并推送 A,但不小心同时提交并推送了 A 和 B
我做了一个“git push old-id:master”所以在 github 上它显示“Master is now old-id”其中 old-id 是我之前的最后一次提交,所以我认为它回到了我之前 promise 。
问题:
- 在我的本地,我如何撤消具有 A 和 B 的提交,并仅提交 A,并仅推送 A?
注意:不过,我确实需要在本地保留 A 和 B 的更改。最终结果应该是:
- 本地 - 新 A 和新 B
- Github - 新 A 和旧 B
最佳答案
$ git reset <old-id> # Undo the commit after old-id
$ git add A # stage A for a new commit
$ git commit # make the new commit
$ git push # push it
关于git revert commit/push 但保留更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10184637/