When Your Mate Deletes Your Files On A Common Project

What happens when your friend removes some of your files because he thought it was not needed and then you want to rebase and it is gone. There are several ways to recover the file, by going to github and checking on its history, but here I will present two methods of how to do this. The first one is via a log command and the second is via a rev-list command.

git log --pretty=oneline -- <file_path> | tac

This way we reverse the output of a git log regarding the file in question. But now let’s look at a more interesting way:

git rev-list -n 1 HEAD -- <file_path>
git checkout <deleting_commit>^ -- <file_path>
// or in one command
git checkout $(git rev-list -n 1 HEAD -- "$file")^ -- "$file"

source: http://stackoverflow.com/questions/953481/restore-a-deleted-file-in-a-git-repo
In case you also want to review more than one commit you can vary the 1 above to include more commits that have to do with the file in question.

Leave a Reply

Your email address will not be published. Required fields are marked *