Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git recover single file that was deleted during a merge

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?

like image 751
tybro0103 Avatar asked Jan 19 '10 19:01

tybro0103


People also ask

How do I recover a deleted file in git?

Recovering Deleted Files with the Command Line Git provides ways to recover a deleted file at any point in this life cycle of changes. If you have not staged the deletion yet, simply run `git restore <filename>` and the file will be restored from the index.

Does git merge delete files?

Git does not apply deleted files when merging an old branch into the master.


1 Answers

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.

like image 72
Bartek Avatar answered Sep 16 '22 15:09

Bartek