Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Files deleted after rebase with git, how to recover?

Tags:

git

I had some files on my project which rebase deleted. I did not commit anything. I lost some important files, how can I recover them?

like image 424
AndreDuarte Avatar asked Oct 08 '14 00:10

AndreDuarte


People also ask

Can we recover deleted files from git?

In this case, you can restore the file using either git checkout or git reflog . You can find the hash-ID of the previous commit from the command: git log . In case you don't have the hash ID, you can use the command git reflog .

How do I undo a git deletion?

You can restore a deleted file from a Git repository using the git checkout command. If you do not know when a file was last deleted, you can use git rev-list to find the checksum of the commit in which that file was deleted. Then, you can check out that commit.


1 Answers

git reflog works wonders in such situations: simply use git reflog and note few recent commits that were active. Then use git checkout commit_id to checkout to any particular commit. Most likely, you need previous commit (current one is one you have screwed up).

Also, if you rebase was not committed yet, you can abort it with git rebase --abort. If it was committed, you can simply kill last commit with git reset --hard HEAD~.

like image 149
mvp Avatar answered Oct 13 '22 00:10

mvp