git revert commit / push但保持更改

时间:2012-04-17 03:28:19

标签: git commit revert

它是这样的:

  • 我有我修改过的文件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 个答案:

答案 0 :(得分:37)

$ 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
相关问题