1

Originally I had commited to the wrong branch, wanted to take that back and commit to the right one (master). I wanted to go the route that is suggested in the accepted answer from How to fix committing to the wrong Git branch?

So I made a soft reset, which as I understand it, leaves the working copy completely untouched

git reset --soft HEAD^

Followed by the attempt to checkout the master

git checkout master

I was told, that certain local changes would be overwritten by the checkout and that I should commit or stash the changes. I choose to stash them. I used the Git Extensions stashing command, which I believe is simply

git stash

At least that is what is shown when I try it on other repositories now. I understand, that this doesn't include untracked files, but it also doesn't clean them out.

Then I switched to the master branch via the Git Extensions GUI. Then I wanted to pop the stash, which failed due to some conflicts, that would arise. And at this point I noticed, that an untracked (but ignored) folder is missing (.\MyScripts). Other untracked (and ignored) files are there (e.g. *.log files)

The difference, that I can see is, that the MyScripts folder is excluded via .git/info/exclude and the *.log files are excluded via .gitignore

Does that make sense to anyone? Where is my MyScripts folder? How to get it back?

Sandro
  • 453
  • 1
  • 5
  • 19
  • Was it ignored before you switched branches? Is it ignore now? Meaning, was the folder listed in .gitignore both before and after you switched branches? – Lasse V. Karlsen Feb 09 '18 at 12:54
  • git didn't touch your MyScripts files if it wasn't tracked and if you didn't run a git clean. So you should find it in the same place you've put it. – Venom Feb 09 '18 at 15:33
  • @LasseVågsætherKarlsen It has never been in any other file, than the .git/info/exclude file. And it was ignored before and I don't know, because it's gone ;-) – Sandro Feb 12 '18 at 10:31
  • @basslo That is what I am thinking, but I can't see it – Sandro Feb 12 '18 at 10:31

1 Answers1

0

Just a note: in question you referred to, the second answer is more sensible - despite fewer votes.

Where is my MyScripts folder? How to get it back?

If you committed it, then it's somewhere in your Git objects database - let's restore it ;)

Start with finding out your commit id before your soft reset:

$ git reflog

Look through commits in there, find the one just before your soft reset and write it down (maybe do git log -1 <commit> to double check if you selected appropriate one).

Now checkout branch, clean up your mess from switching branches, possible failed merge and possible failed stash pop:

$ git checkout master
$ git reset --hard HEAD  # or HEAD~1 if you already committed something broken

And finally, cherry pick hash, that you found in reflog and resolve conflicts as you intend them to be solved:

$ git cherry-pick <commit>
Patryk Obara
  • 1,847
  • 14
  • 19
  • I have to admit, that I simply chose the first option, because it made sense to me (and probably because it had the social proof behind it). And unfortunately it had never been commited, it was all personal development stuff, which no one else would have understood. Thus the personal ignore – Sandro Feb 12 '18 at 10:37
  • You started this question with "I had committed to the wrong branch" - therefore I presumed that was the case. Without commit, reflog won't help you with retrieving your changes, sorry. – Patryk Obara Feb 12 '18 at 10:43
  • No finger pointing, but it says: "And at this point I noticed, that an untracked (but ignored) folder is missing (.\MyScripts). Other untracked (and ignored) files are there (e.g. *.log files)" Have you overlooked it or is my terminology imprecise? – Sandro Feb 12 '18 at 10:45
  • Try `git reflog refs/stash`. Can you find your missing folder in one of stashed commits recorded there? – Patryk Obara Feb 12 '18 at 11:04
  • Nope, can't find anything in those. Also not in the results of `git fsck --unreachable` I would find the text snippet *MyScripts* in there somewhere, right? – Sandro Feb 12 '18 at 11:59