Reset Last Git Commit to HEAD

In our previous article, we used git reset –soft HEAD~1 to undo the last commit without losing changes that were uncommitted. Additionally, we used git reset –hard HEAD~1 to undo everything, even changes that we made locally. But what to do when you want to reset the last Git commit to HEAD, keep the changes that you did in your repo directory, but you don’t want to keep them in the index? Here’s your answer. If you stumble upon situations like the one that we described above, you have to use –mixed flag. Here’s an example. Let’s say that we added some sort of file with our last commit. Now let’s run Git reset command with –mixed flag. What the command above did is the following. It removed the last commit, which in this case was file addition and it removed it from the Git Index, but the file remained in the directory where you are currently located ( which is your local repository directory ). So flag –mixed is actually a combination of –soft and –hard Git reset options. That is why it’s called mixed in the end.

How to Use Git Revert Option to Reset

Revert is a bit different than reset. The main difference is that reset sets a new position for HEAD while revert actually reverts the whole commit which is specified. Let us show you an example of how this actually works. So again, the last thing that we committed was file addition. Let’s run the revert command now. Your default text editor will open now and the output will look like this. Once you are done, exit the text editor, and a new message will pop up. That’s it! You successfully competed Git reset to HEAD action with the revert option.