开发者

Git strange behaviour

git status
# On branch master
# Changed but not updated:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#       modified:   readme.txt
#       modified:   requirements.txt
#
no changes added to commit (use "git add" and/or "git commit -a")

I didn't make any changes on those files. But I'm getting this message 开发者_如何学Pythoneven if I try:

git checkout -- readme.txt
git checkout -- requirements.txt

When I run:

git diff

it shows the whole file as updated. But the contents are the same.

I tried to delete them and checkout again, but it didn't work.


At a guess: line endings. The files probably have different line endings to your OS, which git is handily(!) converting. You can fiddle with the core.autocrlf option to try and fix this behaviour: github has some helpful advice here.

If it is a line endings issue and it's just those files, it may be worth you normalising them to be consistent and the same as the rest of your repository. This may just be a case of committing the changes you're showing now.


If you can avoid any eol conversion , try:

git config --global core.autocrlf false

(my preferred configuration)

, and clone again your repo to see if the issue persist (clean status instead of "all files modified").
If your editors support other eol style and don't make any conversion, you won't be bothered again.


this sort of thing happens with line ending changes (which are not easily visible on a terminal; look at it in a binary editor) or the odd badly-written program that leaves nulls at the end of everything.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜