如何正确编辑git config文件?

时间:2019-02-22 01:29:25

标签: git git-bash

我的主要代码编辑器是VS Code。我没有任何基于Windows的项目,因此我保存所有工作并将行尾设置为LF。

将我的文件添加到git临时区域时,我收到此消息:

warning: LF will be replaced by CRLF

我已经检查了文档和类似的问题,并使用以下命令将core.autocrlf设置为inputgit config --global core.autocrlf input

我的问题是:现在可以在我的git设置文件中同时包含这两行了吗

core.autocrlf=truecore.autocrlf=input吗?

这是整个文件:

$ git config -l
core.symlinks=false
core.autocrlf=true
core.fscache=true
color.diff=auto
color.status=auto
color.branch=auto
color.interactive=true
help.format=html
rebase.autosquash=true
http.sslcainfo=C:/Program Files/Git/mingw64/ssl/certs/ca-bundle.crt
http.sslbackend=openssl
diff.astextplain.textconv=astextplain
filter.lfs.clean=git-lfs clean -- %f
filter.lfs.smudge=git-lfs smudge -- %f
filter.lfs.process=git-lfs filter-process
filter.lfs.required=true
credential.helper=manager
core.editor='C:\Program Files\Microsoft VS Code\Code.exe' --wait
user.email=***
user.name=***
core.autocrlf=input

可以,还是应该删除第二行autocrlf=true?这有点令人困惑,因为我认为上述命令将替换/更新设置中的第二行。

谢谢

编辑:

这是git config -l --show-origin的输出:

$ git config -l --show-origin
file:"C:\\ProgramData/Git/config"       core.symlinks=false
file:"C:\\ProgramData/Git/config"       core.autocrlf=true
file:"C:\\ProgramData/Git/config"       core.fscache=true
file:"C:\\ProgramData/Git/config"       color.diff=auto
file:"C:\\ProgramData/Git/config"       color.status=auto
file:"C:\\ProgramData/Git/config"       color.branch=auto
file:"C:\\ProgramData/Git/config"       color.interactive=true
file:"C:\\ProgramData/Git/config"       help.format=html
file:"C:\\ProgramData/Git/config"       rebase.autosquash=true
file:C:/Program Files/Git/mingw64/etc/gitconfig http.sslcainfo=C:/Program Files/Git/mingw64/ssl/certs/ca-bundle.crt
file:C:/Program Files/Git/mingw64/etc/gitconfig http.sslbackend=openssl
file:C:/Program Files/Git/mingw64/etc/gitconfig diff.astextplain.textconv=astextplain
file:C:/Program Files/Git/mingw64/etc/gitconfig filter.lfs.clean=git-lfs clean -- %f
file:C:/Program Files/Git/mingw64/etc/gitconfig filter.lfs.smudge=git-lfs smudge -- %f
file:C:/Program Files/Git/mingw64/etc/gitconfig filter.lfs.process=git-lfs filter-process
file:C:/Program Files/Git/mingw64/etc/gitconfig filter.lfs.required=true
file:C:/Program Files/Git/mingw64/etc/gitconfig credential.helper=manager
file:C:/Program Files/Git/mingw64/etc/gitconfig core.editor='C:\Program Files\Microsoft VS Code\Code.exe' --wait
file:C:/Users/Wladyslaw/.gitconfig      user.email=***
file:C:/Users/Wladyslaw/.gitconfig      user.name=***
file:C:/Users/Wladyslaw/.gitconfig      core.autocrlf=input

1 个答案:

答案 0 :(得分:1)

There are 3 "levels" of git config – system, global and local。 如您所见,您已在全局配置中将core.autocrlf设置为input,在系统配置中将其设置为true。最后,对于您的用户而言,此var的全局配置将接管系统1,它将为input。除非您也在本地(存储级)配置中进行设置。

是的,这是一种常见的做法。