撤销 Git 提交/推送,但保留更改。

23

大概是这样的:

  • 我有文件A和B,我修改了它们

  • 我只打算提交并推送A,但不小心都提交了,并且推送了A和B

  • 我执行了“git push old-id:master”命令,在Github上显示“Master现在是old-id”,其中old-id是我之前的最后一次提交,所以我认为它回到了我提交之前的状态。

问题:

  • 在我的本地,如何撤消同时包含A和B的提交,只提交A,并只推送A?

注意:我确实需要在我的本地保留A和B的更改。最终结果应该是:

  • 本地 - 新的A和新的B
  • Github - 新的A和旧的B

1
为什么不直接检出之前的B并提交和推送呢? - Ritch Melton
1个回答

40
$ 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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接