默认的 git 配置文件中应该包含什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6515582/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 05:37:35  来源:igfitidea点击:

What should go in a default git config file?

gitgit-configcore.autocrlf

提问by shemnon

There is a bewildering array of options that can be set via git config, and that is just the documented ones. Of all of these options, which ones should every developer have set on their box (like user.email)? And what are the most common ones that should be set in common situations (like core.autocrlf=inputon Windows)? But please stay away from religious arguments (like the only acceptable setting of core.whitespacebeing tab-in-indent).

可以通过 设置一系列令人眼花缭乱的选项,git config只是文档中的选项。在所有这些选项中,每个开发人员应该在他们的盒子上设置哪些选项(如user.email)?在常见情况下(例如core.autocrlf=input在 Windows 上)应该设置哪些最常见的设置?但请远离宗教参数(如唯一可接受的设置core.whitespacetab-in-indent)。

回答by Guildencrantz

Your global git config (~/.gitconfig) should really contain the settings that apply to ALL your repositories. Primarily things like user.name, user.email, core.editor, merge, and diffshould be pretty consistently set. That being said I also like to enable color, core.pager, rerere, rebase.autosquashand a slew of aliases.

您的全局 git 配置 (~/.gitconfig) 应该真正包含适用于您所有存储库的设置。主要像user.name, user.email, core.editor,mergediff应该非常一致地设置。话虽这么说,我也很喜欢启用colorcore.pagerrerererebase.autosquash和别名转换。

[color]
    filemode = false
    diff = auto
    status = auto
    branch = auto
    pager = true
[alias]
    b = branch
    ci = commit
    co = checkout
    cob = checkout -b
    d = diff
    l = log
    lg = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative
    lga = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative --branches
    st = status
    fixup = !sh -c 'git commit -a -m \"fixup! $(git log -1 --format='%s' $@)\"' -
    squash = !sh -c 'git commit -a -m \"squash! $(git log -1 --format='%s' $@)\"' -
    ri = rebase --interactive
    rc = rebase --continue
    pr = push gerrit HEAD:refs/for/master
    mt = mergetool
[user]
    email = REDACTED
    name = Matt Henkel
[core]
    pager = less -FRSX
    excludes = ~/.gitexcludes
    editor = vim
[rerere]
    enabled = true
    autoupdate = true
[rebase]
    autosquash = true
[merge]
    tool = kdiff3
[mergetool "kdiff3"]
    keepBackup = false
    trustExitCode = false
[diff]
    tool = kdiff3

回答by Rob Van Dam

Here is an annotated list of several of the most common config settings. Of course, everybody's environment/language/os/git workflow is different so you will likely have to tweak this somewhat but these are some of the most common config variables.

这是几个最常见的配置设置的带注释的列表。当然,每个人的环境/语言/操作系统/git 工作流程都不同,因此您可能需要稍微调整一下,但这些是一些最常见的配置变量。

[user]
    # these are about the most basic and should pretty much always exist
    email = [email protected]
    name = Your Name
[core]
    # if you use windows
    #autocrlf = true

    # use aggressive compression
    # can make your repo smaller but can also be slow
    compression = 9

    # lets you define a global .gitignore for all those 
    # *.swp, *~, *.o, etc things that you're frequently 
    # sticking in .gitignore
    excludesfile = ~/.gitignore_global

    # tells git to ignore file permission changes
    filemode = false

    # lets you tweak the default pager
    # see `man less` for the meaning of these flags
    pager = 'less -FRSX'

    # probably not a good default for most projects, 
    # but you should uncomment with something based on your needs
    #whitespace = tab-in-indent

[color]
    # this turns on default colors for many commands
    # or you can customize specific colors per command (see [3] for example)
    ui = auto

[rerere]
    # google `git rerere`, basically git remembers your
    # partial merge choices and replays them next time
    enabled = true
    autoupdate = true

[push]
    # lets you say just `git push origin` to push the current branch
    default = current 

[alias]
    # this is the most subjective section 

    # aliases are useful if you either frequently typo certain words
    # or else if you are used to another VC like cvs or svn
    co = checkout
    ci = commit
    st = status
    br = branch -av
    brdel = branch -D

    # Show all of my configured aliases
    aliases = !git config --list | grep 'alias\.' | sed 's/alias\.\([^=]*\)=\(.*\)/\1\ \t => \2/' | sort

    # pretty much everybody has their favorite log format view
    # you can find dozens of variations with a quick google
    # here are couple of the most common (the first is my favorite)
    lg = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative
    hist = log --pretty=format:\"%h %ad | %s%d [%an]\" --graph --date=short

Answer merged from several sources:

从几个来源合并的答案:

  1. https://githowto.com/aliases
  2. https://www.javacodegeeks.com/2013/06/git-configuration-options-you-cant-miss.html
  3. http://michaelwales.com/articles/make-gitconfig-work-for-you/#colored-output
  4. https://wildlyinaccurate.com/useful-git-configuration-items/
  1. https://githowto.com/aliases
  2. https://www.javacodegeeks.com/2013/06/git-configuration-options-you-cant-miss.html
  3. http://michaelwales.com/articles/make-gitconfig-work-for-you/#colored-output
  4. https://wildlyinaccurate.com/useful-git-configuration-items/