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.

  • Can't push to github through proxy
  • I'm primarily a Git user, but have a client who's using Subversion. What are the *very* basics I need to know?
  • How to hide JDBC connection credentials from git?
  • Should initial Git commit contain auto generated files?
  • Working on the same branch in all Git repositores
  • gitignore file but not folder
  • 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.

  • Fatal: Not a gitflow-enabled repo yet. Please run 'git flow init' first
  • Make git master HEAD point to current HEAD of branch
  • Why 'checkout master' takes longer than 'checkout feature-branch'?
  • What to do after typing in commit message for git?
  • How do I fetch my git repository from SourceForge?
  • GitHub error “fatal: bad config file line 1 in .git/config” when in git shell
  • 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 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.

    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.

    Git Baby is a git and github fan, let's start git clone.