Files incorrectly reported modified - git attributes buggy? leading to inconsistent repo

隐身守侯 提交于 2019-12-23 17:12:23

问题


This easily leads to a inconsistent git repository: If a file is committed with crlf line endings with the text attribute unset in the working tree, but the text attribute is set in the repo, the file will be incorrectly shown as modified.

I am reproducing this using Git 1.8.5 on a Mac (Darwin 13.1.0) with core.autocrlf set to false.

The effect is the same as in this question: Git files modified after checkout, reset --hard, etc. even though autocrlf is set to false

All you have to do is to check in a file with CRLF line endings, locally using a different git attributes setting for the file than in the repo.

This little shell scripts will produce an inconsistent git repository starting from a clean repo with a few simple steps.

#!/bin/bash
# creating a git repo "repo"
rm -rf repo
mkdir repo
cd repo
git init
# committing gitattributes with text attribute set for all files
echo "* text" > .gitattributes
git add .gitattributes
git commit -m "added .gitattributes"
# add a file with CRLF line ending with text attribute unset
echo -e "crlf\r" > crlffile
echo "* -text" > .gitattributes
git add crlffile
git commit -m "added crlffile"
git checkout .gitattributes
# now "crlffile" shows as modified, even though it isn't.
# only way to resolve is to modify .gitattributes   
git status crlffile
# crlffile shown as modified.
git checkout crlffile
git status crlffile
# crlffile shown as modified.
git reset --hard
git status
# crlffile shown as modified.
# git diff will report the CR as the difference
git diff 
# but external diff reports no differences.
git difftool --extcmd=diff --no-prompt

The actual reason for the question is that I am frequently experiencing the same problem on windows with msysgit (with core.autocrlf set to false). It seems that egit users working with eclipse commit files the way described here, but I try to understand whether the error is caused by git or egit.

Can other git users please try to replicate the problem with other platforms/versions and confirm/deny that this is a git bug?

EDIT:

If you think this problem already has an answer elsewhere, I would be interested in hearing the answer. "git attributes is causing the problem" is not an exact enough answer for this question. If it is a workaround for a git bug, it should be declared as one.

来源:https://stackoverflow.com/questions/22823004/files-incorrectly-reported-modified-git-attributes-buggy-leading-to-inconsist

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