Can't seem to discard changes in Git

后端 未结 20 1255
傲寒
傲寒 2020-11-29 21:17

After seeing the following from the command line:

# On branch RB_3.0.10
# Changed but not updated:
#   (use \"git add ...\" to update what will b         


        
相关标签:
20条回答
  • 2020-11-29 21:42

    This has been bothering me for a while, almost every repo I'd check out had changes that I couldn't discard. Long story short, I tried all of the above, nothing worked. This is what I did to get things back to normal (on a Mac):

    Completely remove the autocrlf & safecrlf settings from ~/.gitconfig
    Completely remove the autocrlf & safecrlf settings from your repo's local config ./.git/config
    git rm --cached -r .
    git reset --hard
    
    0 讨论(0)
  • 2020-11-29 21:46

    Are you on OSX or Windows? If so, the problem probably is having two files of the same name, with different case. eg. index.htm and Index.htm

    Windows, and by default OSX, uses a case insensitive file system, which conflicts with the case sensitive git.

    0 讨论(0)
  • 2020-11-29 21:46

    My problem is kind of similar here and I just found out that git is tracking the changes in file permission. I tried discarding and resetting the branch but files are still there. Run git config --get --local core.filemode, if it is true then you need to set it as false to turn off tracking of file permissions. Running git config --local core.fileMode false should solve it. You can read more here

    0 讨论(0)
  • 2020-11-29 21:50

    Here is my experience, set following variables in .git/config:

    [core]
        autocrlf = false
        safecrlf = false
        eol = crlf
    

    then run $ git checkout HEAD ., and it works. but $ git checkout -- . not, strange!

    * git version 1.9.3

    0 讨论(0)
  • 2020-11-29 21:51

    I think you need to pass -f

    From the man page (man git-checkout, GIT-CHECKOUT(1)):

    -f, --force
    Proceed even if the index or the working tree differs from HEAD.
    This is used to throw away local changes.

    For instance, discard changes on the current branch and switch to a different branch:

    git checkout -f master
    
    0 讨论(0)
  • 2020-11-29 21:51

    I had .gitattributes with the following content:

    * text=auto eol=lf

    To overcome the issue, edit .gitattributes to remove this line which relaxes line endings. Then git reset --hard HEAD reverted the files and .gitattributes file.

    0 讨论(0)
提交回复
热议问题