git recover single file that was deleted during a merge

branch, git, repository

Solution

Try something like this:

git checkout HEAD -- filename

This will roll your fileback one commit. If you want to go back further to a specific commit, you can use a commit hash or append ^N to the end of the HEAD keyword, e.g. `HEAD^2`.

Problem

I'm currently in branch 'foo'. I just ran `git merge master`. Only problem is there was a certain file in foo that I wanted to keep. Is there a way to get it back but keep all the other changes from merge master?

Original source