0

So one particular branch was pushed to develop, but now I want to revert that and undo all the last commit changes.

Sorry I know this has been covered in many posts but I am somehow stuck at one step.

What I read was I can run the following command

git reset HEAD~1
and also tried this git reset --soft HEAD~1

When I run the below command, I can see in my visual studio that there are a lot of uncommit changes because of the above step, which I actually want to discard since I want to revert these.

Now what shall I do now, if I do undo changes and try to commit, I dont see any option to commit.

Is there any option to undo these changes and just do a commit directly. I might have missed some critical step here but kind of stuck here.

If anyone can share that step please.

Brenda
  • 510
  • 3
  • 13
  • 36

2 Answers2

0

--mixed is the default option for git reset.

With --soft option, changes are there in the index and are staged. With --medium option, index is modified and the changes are unstaged (changes will still be there in the working directory). With --hard option, index is modified and the changes are removed from the working directory as well.

git reset HEAD~1 uses the default --mixed option and marks the changes as unstaged and are present in the working directory.

You can run git reset --hard to clean up the working directory. Please beware that you will permanently lose the changes in the working directory after running this command.

You can refer this link for more details.

Note: Please use git revert <commit> to revert commits.

Shekhar
  • 11
  • 6
0

After you do git reset HEAD~1, the changes in the files will be as if they were not committed (they were, but you're bringing the index back, so it will appear as if they're not).

This means that you're at a point in the history where if you checkout the files, they will be in their pre-commit stage, and that means that if you don't want to keep any of those changes, you can use

git checkout .

Alternatively, you could have used git revert hash_of_commit, which would have created a new commit with the "inverse" of the changes you made, putting the files back to their state.

ChatterOne
  • 3,381
  • 1
  • 18
  • 24