git status shows modifications even with autocrlf=false

感情迁移 提交于 2019-11-27 03:50:19
Brecht Machiels

This seems like a bug in msysgit indeed. As a workaround, try creating a .gitattributes file containing

* -text

This will tell git not to perform EOL conversions on any files.

VonC

Check if you have no .gitattributes file

As mentioned in the "Effect" section of the gitattributes man page, those files can also have an effect on eol and automatic transformation:

text ^^^^^^

This attribute enables and controls end-of-line normalization.
When a text file is normalized, its line endings are converted to LF in the repository.
To control what line ending style is used in the working directory, use the eol attribute for a single file and the core.eol configuration variable for all text files.

Check also your config for core.eol, as mentioned in "How line ending conversions work with git core.autocrlf between different operating systems".

I'm investigating the weird behavior of core.autocrlf in MSysGit, and I found that having:

[core]
    autocrlf = false
    safecrlf = true
    ignorecase = true
    eol = native 

in the global config file and NO core.autocrlf setting in a repo copied from another PC (not cloned, only copied), issuing a git status command results in ALL text files marked as modified (no gitattributes around).

But if you add a local (repository) core.autocrlf setting to true, and then issue a git status command, all the changes disappears and the repository turns back to be clean.

BUT (and this is the strange behavior) if you remove the just added core.autocrlf setting from the repository config file (thus returning to the exact initial state), the git status command continues to report no changes!

Given that no operations has been performed on the repository, only changing a config setting, and reverting back to the original state, has done the trick...

If this isn't a bug, I can't imagine who in the world can call this a "normal" behavior.

Cris Favero

This problem can be caused by gitattributes' text option.

Please read the documentation carefully but essentially autocrlf only matters if text is not set in a .gitattributes:

Unspecified
If the text attribute is unspecified, git uses the core.autocrlf configuration variable to determine if the file should be converted.

Find your .gitattributes file via:

find <root-dir> -name .gitattributes

And grep for text, eol or crlf to find your culprit and revise as necessary.

You may just change this file and revert the change without committing for long enough to get through your issue.

"autocrlf" issue is a typical issue for cross multi platform repo (i.e. using a samba share with tortoisegit over a server under linux)

I realized, that sometimes (often), it's more a "chmod" issue than a autocrlf one : - git status windows display pending modifications - git status linux display nothing

"mode change 100755 => 100644 config/packager.xml"

Check that your "static" files are not +x, (and in this case tortoisegit wont like it)

Although i don't know what is causing this weird behaviour, i know one more way of discarding changes that might work.

Warning! Be extremely careful and do a backup first; this can be highly destructive.

If all data that you care about is committed in the repository, you can simply delete everything in your working directory (of course except hidden .git directory) and run git reset --hard HEAD to have git recreate the working directory solely from the repository data.

Remember to carefully check if you don't have any important data that is not tracked by git before doing this. It's not enough to check git status for uncommitted changes - remember that deleting all files from the working dir will also delete files which you told git to ignore, and they won't be recreated with git reset --hard HEAD because they're not tracked at all.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!