1

I am using Intellij and working on a git project where I'm facing the following problem :

Let's imagine I have an empty git project. And then I do the following operations :

  • Create new file called : NewFile.txt

  • Add and commit (commit id : 1XXXX)

  • Create new file called : MistakeFile.txt

  • Add and commit (commit id : 2XXXX)

Now at this point I realise that I shouldn't have added the MistakeFile. So I do :

git reset HEAD~1

However on my IDE the MistakeFile is still present, while it doesn't exist in the commit I just reseted to. FYI: In this case I haven't pushed anything to the remote repository yet. All commits are local ones.

John Dist
  • 77
  • 10
  • https://stackoverflow.com/questions/3528245/whats-the-difference-between-git-reset-mixed-soft-and-hard – phd Oct 29 '22 at 12:07

1 Answers1

0

This is because you want to reset in hard mode.

git reset HEAD~1 --hard

By default, git resets in mixed mode, this means it only affects the history of the branch but not the files in the working area.

While in hard mode it affects both.

matt
  • 515,959
  • 87
  • 875
  • 1,141
SyncroIT
  • 1,510
  • 1
  • 14
  • 26