Question

I think I might have screwed my days work but I did this chain of commands

git status
git add .
git rm filename1
git rm filename2

I then stupidly thought why am I doing this one by one I know there is a way to do it all at once

git rm -r -f

working directory gets wiped I realised I have messed up and then tried

git checkout -f

which restored everything to my last commit which was this morning.

I am looking at these answers and thinking there might be a way but I dont understand those answers well enough to risk trying anything yet, any advice?

Can a “git rm -r -f ” command be reverted?

How to undo a “ git rm -r -f * ”

Was it helpful?

Solution

Based on the linked answers, everything that you added to index with git add should be possible to recover with:

git fsck --lost-found

This will create the files that you added to the index but never committed in the .git/lost-found/other directory. The filenames will be SHAs instead, so you will have to look inside one by one to know which is which.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top