git tells me that my files are changed, but I can&

2019-02-23 16:58发布

I've just installed the latest Git (1.9.5), and suddenly it tells me that my working tree is not clean (changes are not staged), but I can't see any changes in any of my files in any diff tool (I tried Tortoise and Visual Studio's built in). When I run git status, it says:

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        modified:   inc/i_lab_orders.asp
        modified:   lab_order_list.asp
        modified:   slib/lab_order_lib.asp

However, Git GUI's diff tool tells me that all lines are changed, but I can't spot any difference. Same with the git bash's diff.

Running git reset --hard doesn't help at all -- the command executes w/o any problems, but in the end I still have the same "changed" files.

UPDATE: core.autocrlf is false, core.fileMode is also false. I also noticed that the files that are reported to be changed are exactly the ones that were committed in the last commit.

I'm on Windows.

3条回答
姐就是有狂的资本
2楼-- · 2019-02-23 17:33

Welcome to hell. Enjoy your stay :-)

The difference that you can't see is the line ending. In a nutshell, you have told Git to convert all line endings to Windows or Unix and there is a file in the repo which has different line endings in the repo.

When you check out the file, Git does the conversion, creating a local file which looks correct. When you do a diff, Git doesn't convert (because the file on disk must be correct and why would it convert what is already in the repo?) and now you get differences which aren't there.

Solution: Make sure that Git is configured correctly for every developer who can push, commit the file once with the correct endings and get a silly hat for anyone to wear who creates files with wrong line endings.

Related:

查看更多
唯我独甜
3楼-- · 2019-02-23 17:44

Change may also be file mod, but you can tell git ignore something like this.

git config core.fileMode false

I recommend you use gitk

On ubuntu is just

sudo apt-get install gitk
查看更多
走好不送
4楼-- · 2019-02-23 17:44

Fixed it by manually deleting the .git\rebase-merge-failed folder. Thanks everybody for trying to help me.

UPDATE I also suspect that the cause was that I had text=auto in my .gitattributes file.

查看更多
登录 后发表回答