Git asks me to commit or stash changes on checkout master, even though all changes were committed?

前端 未结 8 1711
误落风尘
误落风尘 2020-12-28 12:48

I have two branches locally, master and Berislav. The latter is currently active, and I have committed all the changes. When I try to checkout to <

相关标签:
8条回答
  • 2020-12-28 12:53

    I had the same problem, and this solved my issues (on Linux):

    git config --global core.autocrlf input
    
    0 讨论(0)
  • 2020-12-28 12:53

    As the message suggests, rerun the command w/ --force option.

    flutter upgrade --force
    
    0 讨论(0)
  • 2020-12-28 12:56

    It seems that you have untracked files in your working copy, which are tracked on the other branch. Git refuses to checkout the other branch, since your currently untracked local files would be overwritten by the files on the other branch.

    You can now

    • Add those files to your current branch, if those files are relevant for this branch
    • remove those files if they are not needed
    0 讨论(0)
  • 2020-12-28 13:05

    I encountered a similar problem today. git status wasn't listing the files which checkout was complaining about. I did a:

    git checkout -- path/to/file
    

    And that undoes any changes to the file.

    An even easier way to undo all unstaged changes on current working directory [1]:

    git checkout -- .
    

    [1] - Be warned - you will lose any other unstaged changes you were working on (if any). If you don't know what you are doing, then keep a backup of the files you were working on :)

    0 讨论(0)
  • 2020-12-28 13:07

    Very similar to @JohnHammink answer but here goes.

    Solution

    1. Remove file to another directory.
    2. Commit your changes (it might show you just removed two files).
    3. Add the file again to the directory.
    4. Commit (you should be able to see only one file being committed).

    In my case this was because of a file that was renamed with only a change to the case. e.g. fooViewModel to FooViewModel. Git kept thinking that the same file was actually two separate files.

    I think this has something to do with Unix being case sensitive while windows not really.

    Hope this helps

    0 讨论(0)
  • 2020-12-28 13:14

    Move the offending file to some other location. Then delete the offending file from your tree. Pull again. then diff the changes from your offending file over the file you just pulled. hack, but it works.

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