git revert commit/push 但保留更改

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10184637/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 06:46:54  来源:igfitidea点击:

git revert commit/push but keep changes

gitcommitrevert

提问by James Gu

It goes like this:

它是这样的:

  • I have files A and B that I modified

  • I'm only suppose to commit and push A, but accidentally committed both and pushed both A and B

  • I did a "git push old-id:master" so on github it shows "Master is now old-id" where old-id is the last commit before me, so i think it's back to before i committed.

  • 我有修改过的文件 A 和 B

  • 我只是假设提交并推送 A,但不小心同时提交并推送了 A 和 B

  • 我做了一个“git push old-id:master”,所以在 github 上它显示“Master 现在是 old-id”,其中 old-id 是我之前的最后一次提交,所以我认为它回到了我提交之前。

Question:

题:

  • On my local, how do i undo the commit that has A and B, and commit only A, and push only A?
  • 在我的本地,我如何撤消具有 A 和 B 的提交,并且只提交 A,并且只推送 A?

Note: I do need to keep the changes for both A and B on my local though. The end result should be:

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

  • Local - new A and new B
  • Github - new A and old B
  • 本地 - 新 A 和新 B
  • Github——新A和旧B

回答by Amber

$ 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