Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Switched Branch After .gitignore and lost .gitinored files

I am new to git, so sorry if this question has already been answered. I'm having trouble finding the answer to this.

I wanted to ignore a set of files that had never been committed before for a commit and used the github app to select them and ignore them. I switched to another branch for a while and when I returned to my branch, my ignored files were gone.

Are these files deleted?

I used git checkout to switch back to the branch and then git status --ignored . My missing files are not there.

like image 567
Betsy Dupuis Avatar asked Feb 21 '13 05:02

Betsy Dupuis


2 Answers

You can do this by using git reflog --all to get the SHA code from when the Github App automatically stashed your ignored files before switching to the other branch. See https://stackoverflow.com/a/8865242/2970321.

For example, I fetched a pull request (/pr/364) using the app (SHA 2ba129d). Before I switched back to gh-pages, it stashed my ignored files (SHA 36edfc6).

finding the SHA code of a dropped stash

So to recover, all I needed to do was:

git checkout 36edfc6

My files magically reappeared, and I was able to safely stash them manually somewhere else before switching back to gh-pages again.

like image 137
alexw Avatar answered Sep 28 '22 06:09

alexw


git doesn't delete files it doesn't care about unless specifically told to do so (by checkout -f in some cases of checking out, or clean). As git knows nothing about them, it can't resurecct them either. Use git stash before moving around and doing possibly damaging stuff. Consider carefully which files go into .gitignore, add all non-automatically-generated files to version control.

like image 45
vonbrand Avatar answered Sep 28 '22 07:09

vonbrand