Adding file to git's stage does nothing and cannot be committed

前端 未结 2 1788
清歌不尽
清歌不尽 2021-02-05 03:32

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         


        
相关标签:
2条回答
  • 2021-02-05 04:04

    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`

    0 讨论(0)
  • 2021-02-05 04:07

    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"
    
    0 讨论(0)
提交回复
热议问题