-1

to perform uncommit operation on my code. I did:

git reset --hard demo1.txt

but it is showing :

fatal: Cannot do hard reset with paths.

I also tried this one:

git reset --soft demo1.txt

but showing the same result:

fatal: Cannot do soft reset with paths.

I am a bit new to git. so couldn't able to figure it out. what's wrong ?

Please help me resolve it.

1 Answers1

1

You are trying to uncommit a file, which won't work. If you want to uncommit your last commit (as seen at the top of git log --stat), do a

git reset HEAD~1

It will leave your changes uncommitted. If you don't care about those changes, you can instead remove them with

git reset --hard HEAD~1
neu242
  • 15,796
  • 20
  • 79
  • 114
  • 1
    If you want to change only one file: perform `git reset HEAD~1` as here and then do a `git checkout demo1.txt` to checkout the uncomitted changes and then a new commit of all the other changed files will finish it off. – SamBob Oct 05 '21 at 11:50