0

I ran git reset --soft "HEAD^6" by mistake on my local repo after that I ran git reset --soft "HEAD^"

Now i can find more than 100 file with local changes

What git reset --soft "HEAD^6" does it mean ?

Edit: for those who will ask why i did that, it was a typo.

phd
  • 82,685
  • 13
  • 120
  • 165
Melad Basilius
  • 3,847
  • 10
  • 44
  • 81
  • 1
    Did `git reset --soft "HEAD^6"` succeed? I'm asking because `HEAD^6` means the 6th parent of `HEAD`. It has little chance to be a valid ref as an octopus merge with as many as 6 branches is very rare. Maybe a typo of `HEAD~6`? – ElpieKay Apr 09 '19 at 12:07
  • @MeladEzzat Can you show the output you had on the command? Sorry to doubt your word, but I find it unlikely that you had anything else than "fatal: ambiguous argument 'HEAD^6': unknown revision or path not in the working tree." Isn't it the case? – Romain Valeri Apr 09 '19 at 12:16
  • @ElpieKay and RomainValeri, you are correct it wasn't successful, it was "fatal: ambiguous argument 'HEAD^6': unknown revision or path not in the working tree. Use '--' to separate paths from revisions, like this:". but still i have more than 100 changed file – Melad Basilius Apr 09 '19 at 12:21

3 Answers3

6

About reset --soft

git reset --soft <commitHash> will move HEAD without changing the state of your files (doc).

That's why git status suddenly sees differences. It now compares your (unchanged) code with an older reference. But your files did not change when you did the two last operations.


About the refspec HEAD^6

HEAD^6 will try to point to the 6th parent of HEAD commit. This will fails in most situations. That is, unless your HEAD commit is the result of an (at least) 6-headed octopus merge. I guess we can rule this out.


Conclusion

So the second operation failed and was a no-op. If your first reset was intended, you're good to go!

Romain Valeri
  • 19,645
  • 3
  • 36
  • 61
2

As others mentioned it changes HEAD to the 6th parent. To go back to the previous state you can reset to the your remote with git reset --hard origin/<branch>. If you haven't pushed out your changes look at git reflog then do git reset --hard <sha>.

EncryptedWatermelon
  • 4,788
  • 1
  • 12
  • 28
  • 1
    I was about to add that also, but then I realized... OP didn't state that the first `reset` was unwanted, and the *second one* wasn't actually performed. So no `reset` necessary at this point. – Romain Valeri Apr 09 '19 at 12:27
-1

git reset --soft "HEAD^6" reverts last 6 commits into working dir. if your changes are pushed into remote you can come back to previous state by git reset --hard origin/<<branch>>

Tomasz Białecki
  • 1,041
  • 6
  • 10
  • 1
    Did you confuse `HEAD^6` with `HEAD~6`? The latter *will* point back 6 commits, but not the former. – Romain Valeri Apr 09 '19 at 12:07
  • @RomainValeri explanation for you https://stackoverflow.com/questions/2221658/whats-the-difference-between-head-and-head-in-git – Tomasz Białecki Apr 09 '19 at 12:12
  • 1
    "Explanation for me"?! I precisely explained it already in my answer, then I repeated the idea to *you* in my comment, and even then you did *not* apply what you're linking here. I'm confused, what did I miss? – Romain Valeri Apr 09 '19 at 12:20