Git: How to revert 2 files that are stubbornly stuck at “Changed but not committed”?

后端 未结 12 725
北海茫月
北海茫月 2020-12-22 19:15

I have a repo that has two files that supposedly I changed locally.

So I\'m stuck with this:

$ git status
# On branch master
# Changed but not update         


        
12条回答
  •  一整个雨季
    2020-12-22 19:47

    I spent hours trying to solve a similar issue - a remote branch that I had checked out, which stubbornly showed four files as 'Changed but not updated', even when deleting all files and running git checkout -f again (or other variations from this post)!

    These four files were necessary, but certainly hadn't been modified by me. My final solution - persuade Git that they had not been changed. The following works for all checked out files, showing 'modified' status - make sure you have already committed/stashed any that have really been modified!:

    git ls-files -m | xargs -i git update-index --assume-unchanged "{}"
    

    On Mac OSX, however xargs operates a little bit different (thx Daniel for the comment):

    git ls-files -m | xargs -I {} git update-index --assume-unchanged {}
    

    I've added this as a placeholder for myself for next time, but I hope it helps someone else too.

    -Al

提交回复
热议问题