简体   繁体   English

如何撤消对Git中某些跟踪文件的已提交和推送的更改?

[英]How do I undo my committed and pushed changes to some of the tracking files in Git?

I am a newbie in Git. 我是Git的新手。 I did a mistake and now need to undo the same mistake. 我犯了一个错误,现在需要撤消相同的错误。 I cloned from a remote repository and that brought down fileA and fileB in my working directory. 我是从远程存储库克隆的,它在我的工作目录中关闭了fileA和fileB。 I made a commit and in that commit, I modified fileA and fileB from what is on the server. 我进行了提交,并且在该提交中,我从服务器上的内容修改了fileA和fileB。 (These changes shouldn't go to production). (这些更改不应该投入生产)。

I also pushed the commit to a remote branch of the origin server. 我还将提交推送到原始服务器的远程分支。

Now I need to do two things: 现在,我需要做两件事:

  1. In my next commit, I need to bring those two files to their original state. 在我的下一个提交中,我需要将这两个文件恢复到原始状态。
  2. Push that commit again to the remote branch of the origin. 再次将该提交推送到源的远程分支。

How do I do this? 我该怎么做呢? Any help will be highly appreciated. 任何帮助将不胜感激。

If you need to undo the last commit and keep the changes then do reset . 如果您需要撤消上一次提交并保留更改,请reset

$ git checkout <your-branch>
$ git reset --soft HEAD~1            # undo last commits, and you've changes that you done.

now do change/fix

$ git commit -am 'new-message'       # add & commit your changes
$ git push -f origin HEAD            # force push to master  

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM