Can't seem to discard changes in Git

后端 未结 20 1257
傲寒
傲寒 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:52

    I was working on a libGDX project on Android Studio and I wanted to discard all the changes that I have done, and nothing was working for me, the solution I came up with was to commit all the changes into a new branch

    git checkout -b TRASH
    git add .
    git commit -m "discarded changes"
    git checkout master
    

    and then you can delete the TRASH branch if you want.

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

    I've had a similar issue, where it wouldn't allow me to discard files which either does not exist or has been changed. I use Visual Studio at work, and I found that this happens when switching branches while the app is running.

    git checkout and trying to discard did not help. It wouldn't work or it would just tell me that I do not have permission.

    Solution that worked:

    1. Go into Safe Mode
    2. Discard files

    Restarting is a pain, but this worked faster than trying out 100 things.

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

    For me this issue came up with a combination of downloading an Git-LFS image that was uploaded via Netlify CMS and served differently by their Netlify Large Media handler.

    My solution was to comment out/remove these rows from my ~/.gitconfig so that they look like below, and then checking git status again.

    # [filter "lfs"]
    #   clean = git-lfs clean %f
    #   smudge = git-lfs smudge %f
    #   required = true
    

    OR you can probably add a more local filter via a .gitconfig in the repo root and somehow overwrite the filter rules for lfs there.

    Hope this helps a fellow out.

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

    There is a easy solution. If this happens (normally from unexpected windows shutdown or memory dump) and you cannot discard your changes and even switch between branches (Git says you don't have enough permission); in Windows environment show all hidden files and folders from folder options. Go to your GIT directory (should be start with .git) and delete the "index.lock" file. Then Git should let you do whatever you want to do.

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

    In my case I could not discard changes related to a directory. e.g. when I ran a git diff I would see this: -Subproject commit fdcccccccccccccccccccccccccccccccccccccc +Subproject commit f1bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb

    So I called that directory and ran a git status in there. It was in a HEAD detached state. And then I just ran a git checkout master in there. That set things right for me. But this is not helpful for the exact scenario asked in here.

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

    Many of these answers solve the problem for one of many issues. Thus, you may have to try a few until you find the one that was the problem. So, I'll add my own experience to the mix.

    In my case, the issue was that I had a global ~/.gitattributes file in my ~/.gitconfig. When I finally examined that file, I was able to find the problematic extension and rectify it manually.

    Specifically for problematic repo I was dealing with, *.bat needed be -text eol=crlf instead of text eol=crlf.

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