Git refuses to reset/discard files

前端 未结 4 1626
不思量自难忘°
不思量自难忘° 2020-12-04 06:57

I have a project with certain js files which I cannot update. I run OSX locally and my remote/staging server is Linux (CentOS).

Right after cloning my project locall

4条回答
  •  死守一世寂寞
    2020-12-04 07:26

    This issue repeatedly popped up with the Roll20 character sheets repository on an Ubuntu machine and I could solve it by

    #!/bin/sh
    
    # Use in root dir of git repository
    # Fixes some newline-related weirdness
    git rm --cached -r .
    git reset --hard
    

    But, this stopped resolving the issue completely today and by looking around Stack Overflow I found the culprit to be their .gitattributes file:

    # Auto detect text files and perform LF normalization
    * text=auto
    

    After git pull origin master, git status returned:

    On branch master
    Your branch is up-to-date with 'origin/master'.
    Changes not staged for commit:
      (use "git add ..." to update what will be committed)
      (use "git checkout -- ..." to discard changes in working directory)
    
        modified:   Star Wars Revised RPG/SWRRPG-updated.html
    
    no changes added to commit (use "git add" and/or "git commit -a")
    

    The solution was to remove the * text=auto line from the .gitattributes:

    $ git status
    On branch master
    Your branch is up-to-date with 'origin/master'.
    Changes not staged for commit:
      (use "git add ..." to update what will be committed)
      (use "git checkout -- ..." to discard changes in working directory)
    
        modified:   .gitattributes
    
    no changes added to commit (use "git add" and/or "git commit -a")
    

    The changes on .gitattributes can be discarded and Git will still be satisfied.

    Edit +1d: Retried the .gitattributes "trick" today, but did not git status before discarding the .gitattributes changes. For no reason obvious to me (maybe caching of git status?), a git status afterwards returned this again:

    On branch master
    Your branch is up-to-date with 'origin/master'.
    Changes not staged for commit:
      (use "git add ..." to update what will be committed)
      (use "git checkout -- ..." to discard changes in working directory)
    
        modified:   Star Wars Revised RPG/SWRRPG-updated.html
    
    no changes added to commit (use "git add" and/or "git commit -a")
    

    Doing it again, but with git status inbetween worked.

提交回复
热议问题