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.
2 Solutions collect form web for “Switched Branch After .gitignore and lost .gitinored files”
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
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
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
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.