True Believer
True Believer

Reputation: 139

How to undo git rm . -r --cached command without losing any uncommitted changes?

I've accidentally executed a git rm . -r --cached command which makes all files have deleted status. I have some uncommitted changes which I do not want to lose. How can I undo the effects of git rm . -r --cached command and return to the previous state without losing any uncommitted changes?

Upvotes: 2

Views: 2962

Answers (2)

Luís Brito
Luís Brito

Reputation: 1772

Just add them again with: git add .

The command you ran doesn't remove the files from the disk, just from the index. So, add them back.

Upvotes: 3

YSC
YSC

Reputation: 40070

Since you used the --cached option, only your index has been modified. Your working directory has been left as is. You can simply git add files marked as deleted.

Upvotes: 7

Related Questions