I am new to Git and I think I removed files on my local accidentaly. I used this command git rm -r --cached . and it removed the files. But I didn't commit it yet.
How can I undo it?
I am new to Git and I think I removed files on my local accidentaly. I used this command git rm -r --cached . and it removed the files. But I didn't commit it yet.
How can I undo it?
git rm documentation is kind of clear:
--cached
Use this option to unstage and remove paths only from the index. Working tree files, whether modified or not, will be left alone.
So if you lost files it's because there was already commits existing on the repository (not yours, but others ones).
Try to run git reset it should clear all your not committed actions, so you should find the repository like it was before this.
The index contains a path and an object id. git rm --cached erases the index entry, undoing the act means putting it back the way it was.
If the content was unchanged since checkout, git reset -- path/to/it is your ticket. If you git added the content, it's in the repository but the association between path and content is lost, you can find objects in .git/objects created about the right time and git show them to find the right one, then git update-index --add --cacheinfo 10644,objectidhere,path/to/it to restore the index entry manually.
edit: or if you haven't edited the content in your worktree since git checkout or any later git add, then just git add it again.