简体   繁体   中英

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

I am a newbie in 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. I made a commit and in that commit, I modified fileA and fileB from what is on the server. (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 .

$ 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  

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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