简体   繁体   English

Git 配置文件:最佳实践

[英]Git config files: Best practice

I managed somehow to make Git running with Github and now (a year later) I would like to teach the group how they can do the same.我设法让 Git 与 Github 一起运行,现在(一年后)我想教小组如何做同样的事情。 I learned quite a lot from here , but even with the answer, some things remain unclear.我从这里学到了很多东西,但即使有了答案,有些事情仍然不清楚。 Please apologize, if I didn't got it from the git reference请道歉,如果我没有从git 参考中得到它

Questions :问题

  • Is there a best practice, which parameters should show up in which config file?是否有最佳实践,哪些参数应该显示在哪个配置文件中?

... Continued from my example below: ...从我下面的例子继续:

  • I marked the parts which I can access via --system , --global and --local .我标记了我可以通过--system--global--local访问的部分。 Does anybody know where the first part belongs to?有谁知道第一部分属于哪里?
  • Green is everything, where I think, it is ok (with my very limited knowledge).绿色是一切,我认为,没关系(以我非常有限的知识)。
  • Red is strange as it exists twice红色很奇怪,因为它存在两次

When I run git config --list --show-origin I get the following result:当我运行git config --list --show-origin我得到以下结果:

在此处输入图片说明

Edit @Code-Apprentice :编辑@代码学徒
From git-bash来自 git-bash

$ git config --list --show-origin --system
file:"C:\\Git\\mingw64/etc/gitconfig"   credential.helper=manager

and cmd和 cmd

>git config --list --show-origin --system
file:"C:\\Git\\mingw64/etc/gitconfig"   credential.helper=manager

Git output as code : Git 输出为代码

file:"C:\\ProgramData/Git/config"       core.symlinks=false # ... see .git/config 
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"       http.sslcainfo=C:/Git/mingw64/ssl/certs/ca-bundle.crt
file:"C:\\ProgramData/Git/config"       diff.astextplain.textconv=astextplain
file:"C:\\ProgramData/Git/config"       rebase.autosquash=true

file:"C:\\Git\\mingw64/etc/gitconfig"   credential.helper=manager # ... see file:C:/Users/myname/.gitconfig

file:C:/Users/myname/.gitconfig    filter.lfs.clean=git-lfs clean %f
file:C:/Users/myname/.gitconfig    filter.lfs.smudge=git-lfs smudge %f
file:C:/Users/myname/.gitconfig    filter.lfs.required=true
file:C:/Users/myname/.gitconfig    user.name=My name
file:C:/Users/myname/.gitconfig    user.email=my.name@domain.com
file:C:/Users/myname/.gitconfig    credential.helper=wincred
file:C:/Users/myname/.gitconfig    alias.hist=log --pretty=format:'%h - %an, %ad: %s' --graph --date=short
file:C:/Users/myname/.gitconfig    difftool.kdiff3.cmd='C:/Program Files/KDiff3/kdiff3' $LOCAL $REMOTE
file:C:/Users/myname/.gitconfig    difftool.kdiff3.keepbackup=false
file:C:/Users/myname/.gitconfig    difftool.kdiff3.trustexitcode=false
file:C:/Users/myname/.gitconfig    merge.conflictstyle=diff3

file:.git/config        core.repositoryformatversion=0
file:.git/config        core.filemode=false
file:.git/config        core.bare=false
file:.git/config        core.logallrefupdates=true
file:.git/config        core.symlinks=false
file:.git/config        core.ignorecase=true
file:.git/config        core.hidedotfiles=dotGitOnly
file:.git/config        remote.origin.url=https://github.com/repo/Rettung-ZCH
file:.git/config        remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
file:.git/config        branch.master.remote=origin
file:.git/config        branch.master.merge=refs/heads/master
file:.git/config        branch.dev1.remote=origin
file:.git/config        branch.dev1.merge=refs/heads/dev1
file:.git/config        branch.dev2.remote=origin
file:.git/config        branch.dev2.merge=refs/heads/dev2
  • Is there a best practice, which parameters should show up in which config file?是否有最佳实践,哪些参数应该显示在哪个配置文件中?

This is totally up to you, whether you want a setting only on one repository, on all repositories you access with your user account or on all repositories on this machine (each time of course only if not overwritten from a lower config level).这完全取决于您,无论您只想在一个存储库上、在您使用用户帐户访问的所有存储库上还是在这台机器上的所有存储库上进行设置(当然,每次只有在没有从较低的配置级别覆盖的情况下)。

  • I marked the parts which I can access via --system, --global and --local.我标记了我可以通过--system、--global 和--local 访问的部分。 Does anybody know where the first part belongs to?有谁知道第一部分属于哪里?

As far as I remember these are the default values of the Git for Windows client and are on (or rather above) the system settings level.据我所知,这些是 Windows 客户端的 Git 的默认值,并且处于(或更确切地说)系统设置级别。 You can list and change them with git config --file c:\\ProgramData\\Git\\config --list and so on.您可以使用git config --file c:\\ProgramData\\Git\\config --list等列出和更改它们。

  • Green is everything, where I think, it is ok (with my very limited knowledge).绿色是一切,我认为,没关系(以我非常有限的知识)。

As I said, totally up to you.正如我所说,完全取决于你。 The local green settings are most probably only useful on the local level, yes.本地绿色设置很可能仅在本地级别有用,是的。 For me user.email for example is not set on global level on my work box, as I work on private and corporate repos and use different addresses there.对我user.email ,例如user.email没有在我的工作箱上设置全局级别,因为我在私人和公司存储库上工作并在那里使用不同的地址。 By not configuring either on the global level I am reminded on local level to set it when doing the first commit.通过不在全局级别进行配置,我会在本地级别被提醒在第一次提交时进行设置。

  • Red is strange as it exists twice红色很奇怪,因为它存在两次

You can have each setting on each level, lower level overwriting value of upper levels, this is perfectly legal.您可以在每个级别上进行每个设置,较低级别覆盖较高级别的值,这是完全合法的。 You can eg set for all users on the system to use credential.helper=manager but for your user to use credential.helper=wincred like you have it in your example.例如,您可以将系统上的所有用户设置为使用credential.helper=manager但让您的用户使用credential.helper=wincred就像您在示例中所使用的那样。

For Windows there should be following global settings:对于 Windows,应该有以下全局设置:

rem always have Linux line endings in text files
git config --global core.autocrlf input
rem support more than 260 characters on Windows
rem See https://stackoverflow.com/a/22575737/873282 for details
git config --global core.longpaths true
rem some color and diff tweaks
rem   Use SVN's ||| also in git
rem   See https://git-scm.com/docs/git-config#Documentation/git-config.txt-mergeconflictStyle for details
git config --global merge.configStyle "diff3"
git config --global color.diff.new "green bold"
git config --global color.status.updated "green bold"
git config --global color.branch.current "green bold"
rem Sort branches at "git branch -v" by committer date
git config --global branch.sort -committerdate

(The hints at https://stackoverflow.com/a/24045966/873282 are obsolete) https://stackoverflow.com/a/24045966/873282上的提示已过时)

Git will override more global settings with more local ones. Git 将使用更多本地设置覆盖更多全局设置。 The duplicated (red) ones in your output guarantee consistency at a more local level if the more global value is ever changed.如果更全局的值发生过更改,则输出中的重复(红色)值可确保更本地化的一致性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM