【问题标题】:What should go in a default git config file?默认的 git 配置文件中应该包含什么?
【发布时间】:2011-09-24 19:51:16
【问题描述】:

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

【问题讨论】:

    标签: git git-config core.autocrlf


    【解决方案1】:

    您的全局 git 配置 (~/.gitconfig) 应该真正包含适用于所有存储库的设置。主要是 user.nameuser.emailcore.editormergediff 之类的设置应该非常一致。话虽如此,我也喜欢启用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
    

    【讨论】:

    • 您认为您可以解释和证明每个项目,而不是“给我看你的,我给你看我的”吗?这似乎是一个非常长的列表,充满了个性化。哪些应该进入“每个”配置?
    • 每个人,就像每个人一样,可能只是:user.name、user.email、core.editor、merge 和 diff。我只是简单地包含了我的通用共享全局配置以供参考。
    【解决方案2】:

    这里是几个最常见的配置设置的注释列表。当然,每个人的环境/语言/os/git 工作流程都不同,因此您可能需要对其进行一些调整,但这些是一些最常见的配置变量。

    [user]
        # these are about the most basic and should pretty much always exist
        email = your-email@example.com
        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
    

    多个来源的答案合并:

    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/

    【讨论】:

      猜你喜欢
      • 2011-08-18
      • 2012-05-10
      • 2016-11-26
      • 1970-01-01
      • 2021-05-17
      • 2017-01-13
      • 2013-11-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多