如何让git更改工作目录中的行?

时间:2013-01-15 19:15:12

标签: git

我在配置了git config --global core.autocrlf false的Windows上使用git,这样git就不会自动将结账时的文件从LF行结尾转换为CRLF。

当我在Windows上创建一个新文件并添加它时,我得到以下输出。

git add windows-file.txt
warning: CRLF will be replaced by LF in windows-file.txt.
The file will have its original line endings in your working directory.

当windows-file.txt被添加到我想要的git索引时,git正在将我的行结束从windows更改为unix。

我遇到的问题是工作目录版本没有改变,如何配置git以便它改变工作目录和git索引的行结尾?

更新

添加后,提交git状态没有显示任何差异,即使本地工作目录版本具有Windows行结尾且repo版本具有unix行结尾。

UPDATE 回购根目录中.gitattributes的内容

# Set default behaviour, in case users don't have core.autocrlf set.
text eol=lf

# These files are text and should be normalized (convert crlf => lf)
*.java       text
*.xml        text
*.cmd        text
*.sh         text
*.txt        text
*.md         text
*.js         text
*.jsp        text
*.html       text
*.htm        text
*.vm         text
.project     text
.classpath   text
*.properties text
*.txt        text
*.bat        text
*.launch     text

# Denote all files that are truly binary and should not be modified.
*.png    binary
*.jpg    binary
*.jar    binary
*.class  binary
*.gz     binary
*.tar    binary
*.dll    binary
*.exe    binary
*.zip    binary

1 个答案:

答案 0 :(得分:5)

如果没有未提交的更改,请尝试:

git rm --cached -r . 
git reset --hard

删除本地文件并从索引中获取它们。