1

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.

Geek
  • 26,489
  • 43
  • 149
  • 227
  • 1
    Possible duplicate of [How to undo last commit(s) in Git?](http://stackoverflow.com/questions/927358/how-to-undo-last-commits-in-git) – Ruslan Osmanov Nov 30 '16 at 12:23

1 Answers1

2

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  
Sajib Khan
  • 22,878
  • 9
  • 63
  • 73