Undo git rm -r --cached

Running git checkout HEAD path/to/file will not work if the file is removed from the cache.

What worked for me is to move to a new branch by running the command:

git checkout -b newBranch

If you've run only git rm -r --cached, try doing a git reset HEAD . from within your repo root.

If you did a git commit -m "msg" after doing a git rm -r --cached, i.e., you committed the changes, then do git reset HEAD~1 to undo your last commit.


If you want git to make git "retrack" your files, that once where removed by .gitignore or by

git rm --cached

you can do it so by using:

git add -f <files>

After that if you want to remove files from the staged area you can use:

git restore --staged <files>

Git works based on file caching so if you removed everything from the cache you can just reverse the whole process by executing .This will add back the files that were being tracked and tell which ones have been modified since the last commit .

> git add . 

Tags:

Git