Alex Rivera | Logout

git recover single file that was deleted during a merge

Asked 2010-01-19T19:42:09.113
44

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?

Edit
Report

1 Answer

49

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.

answered 2010-01-19T19:52:22.837

Your Answer