git stash restores some, but not all, changes

While working on Branch A, a fire erupted in the office that required extinguishing. I did not yet want to commit my changes. I had added 2 new files, and altered 7. None of the changes were staged. I wanted to temporarily stash my changes, and used ‘git stash -a’. What I’d really wanted was the -u switch, but erroneously used -a. My entire project was stashed and my branch was, as expected, restored to the last commit.

I switched to Branch B, did some work, and committed it.

  • Make a git repository that anyone can commit to directly
  • Git committing unchanged files
  • git checkout --patch by words?
  • Git patch of empty commits
  • How can I combine my separate repo as if it started off as a fork?
  • .gitignore two or more extensions file
  • I then switched back to Branch A, and called ‘git stash pop’. Many repetitive lines scrolled by reading “[filename] already exists, no checkout”, and then finalizing with the message “Could not restore untracked files from stash”. Examination of my branch showed that the 2 untracked files HAD been restored, but the 7 altered ones had not. ‘git status’ shows 2 untracked files, and no other changes. Because I’d stashed the entire project, there are roughly 1500 files being compared, so I don’t know what the result of the comparison with the 7 altered files shows… it scrolls off the buffer.

    ‘git stash list’ shows that there is still an entry in the stash:
    “stash@{0}: WIP on Branch A: ffef125 [last commit message]”

    ‘git stash show’ does indeed show my 7 changed files in the stash, but when I ‘git stash pop’, those files are not restored, and the entry remains in the stash (which is not consistent with my expectations for pop)

    I’d wondered if there’d been some kind of merge conflict with the 7 altered files, but there are no conflict resolution markers in any of them.

    Why can I not restore my 7 altered files, and what’s the workaround? And on a side note, why does git say that it could not restore the untracked files, when in fact those are the things that WERE restored?

  • Squashing and reorganizing commits
  • How to mount a filesystem.git directory during init?
  • Preserve git --assume-unchanged files between branch checkouts
  • Syntax Highlighted Diffs
  • How to push with git to github on Windows?
  • Git pull with rebase causing excessive conflicts. How can I fix our workflow?
  • One Solution collect form web for “git stash restores some, but not all, changes”

    Problem solved.

    I resolved this issue by

    1. Checking out the stash branch
    2. Copying the files I wanted into a temp directory
    3. Checking out my original working branch
    4. Copying the reserved files into my working branch

    It’s not entirely clear why the problem occurred in the first place, however. Based on conversations I’ve had with people more git-fluent than I am, it may have had something to do with the fact that the most recent commit was a merge AND that I had not staged any of my changes. But again, that’s pure conjecture.

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