首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >默认的git配置文件中应该包含什么内容?

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

Stack Overflow用户
提问于 2011-06-29 11:54:22
回答 2查看 12.9K关注 0票数 7

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

EN

回答 2

Stack Overflow用户

发布于 2011-06-29 12:09:34

您的全局git配置(~/.gitconfig)应该包含适用于所有存储库的设置。首先,像user.nameuser.emailcore.editormergediff这样的东西应该设置得相当一致。也就是说,我还喜欢启用colorcore.pagerrerererebase.autosquash和一系列别名。

代码语言:javascript
复制
[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
票数 9
EN

Stack Overflow用户

发布于 2015-01-27 02:56:55

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

代码语言:javascript
复制
[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/
票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6515582

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档