I have gotten myself into a bizarre situation where in one of my branches a web.config file cannot be added to the stage. The output of
git add path/to/web.confi
Typically when git gets into a confused state, removing and re-adding the file to the cache will fix it:
git rm --cached foo
It seems the most common way that a file gets in the confused state, is when performing a mv
from the command line.
I've found that using git mv
instead of mv
helps to prevent running into this issue.
http://linux.die.net/man/1/git-mv
Lastly, If you are going to delete a file from a git repository, use git rm
instead of just rm
Why use 'git rm' to remove a file instead of 'rm'?
https://www.kernel.org/pub/software/scm/git/docs/git-rm.html`
The final solution to this particular problem was to remove both web.config entries from the git cache, commit any changes, and re-add the desired Web.config file back to git.
git rm --cached path/to/Web.config
git rm --cached path/to/web.config
git commit -m "Repair confused cache"
git add path/to/Web.config
git commit -m "Add Web.config"