Git:重置git配置文件的最简单方法 [英] Git: Easiest way to reset git config file

查看:265
本文介绍了Git:重置git配置文件的最简单方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我终于可以开始学习git了.但是,我不明智地开始通过Sourcetree回想一下(在我真正知道自己在做什么之前).现在,我正在尝试通过它,我有一个很大的设置列表.当我输入:

I am finally getting around to learning git. However, I unwisely started messing around with it awhile back (before I really knew what I was doing) via Sourcetree. Now that I'm trying to go through it, I have a pretty large list of settings. When I input:

git config --list

我得到以下结果:

core.excludesfile=~/.gitignore
core.legacyheaders=false
core.quotepath=false
core.pager=less -r
mergetool.keepbackup=true
push.default=simple
color.ui=auto
color.interactive=auto
repack.usedeltabaseoffset=true
alias.s=status
alias.a=!git add . && git status
alias.au=!git add -u . && git status
alias.aa=!git add . && git add -u . && git status
alias.c=commit
alias.cm=commit -m
alias.ca=commit --amend
alias.ac=!git add . && git commit
alias.acm=!git add . && git commit -m
alias.l=log --graph --all --pretty=format:'%C(yellow)%h%C(cyan)%d%Creset %s %C(white)- %an, %ar%Creset'
alias.ll=log --stat --abbrev-commit
alias.lg=log --color --graph --pretty=format:'%C(bold white)%h%Creset -%C(bold green)%d%Creset %s %C(bold green)(%cr)%Creset %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative
alias.llg=log --color --graph --pretty=format:'%C(bold white)%H %d%Creset%n%s%n%+b%C(bold blue)%an <%ae>%Creset %C(bold green)%cr (%ci)' --abbrev-commit
alias.d=diff
alias.master=checkout master
alias.spull=svn rebase
alias.spush=svn dcommit
alias.alias=!git config --list | grep 'alias\.' | sed 's/alias\.\([^=]*\)=\(.*\)/\1\     => \2/' | sort
include.path=~/.gitcinclude
include.path=.githubconfig
include.path=.gitcredential
diff.exif.textconv=exif
credential.helper=osxkeychain
core.excludesfile=/Users/myusername/.gitignore_global
difftool.sourcetree.cmd=opendiff "$LOCAL" "$REMOTE"
difftool.sourcetree.path=
mergetool.sourcetree.cmd=/Applications/SourceTree.app/Contents/Resources/opendiff-w.sh "$LOCAL" "$REMOTE" -ancestor "$BASE" -merge "$MERGED"
mergetool.sourcetree.trustexitcode=true
user.name=My Name
user.email=myemail@email.com

这似乎比我想开始的要多,因为我正在研究的教程并没有把所有这些都考虑在内.

And that seems like more than what I want to start with since the tutorial that I'm working through doesn't pull all of that up.

是否可以将配置文件重置"为默认状态?

Is there a way to "Reset" the config file to a default state?

推荐答案

请注意, git config --list 确实显示了两者

Note that git config --list does display both

  • 系统(< path/to/git/config> ),表示已安装Git的位置.
    (默认情况下,在Windows上: C:\ Program Files \ Git )
  • 全局( $ HOME/.gitconfig ).
    在Windows上, $ HOME 将为%USERPROFILE%
  • 和本地( path/to/repo/.git/config )设置.
  • the system (<path/to/git/config>), meaning where Git has been installed.
    (By default, on Windows: C:\Program Files\Git)
  • global ($HOME/.gitconfig).
    On Windows, $HOME would be %USERPROFILE%
  • and local (path/to/repo/.git/config) settings.

要查看已添加到存储库中的文件:

To see the ones you have added to your repo:

git config --local --list

要删除多个值:

git config [<file-option>] --unset-all name [value_regex]
git config [<file-option>] --remove-section name

例如: git config --local --remove-section别名将摆脱别名.

这比删除 .git/config 文件更加精确.

That is a bit more precise that just getting rid of the .git/config file.

为什么 git config --local --list 不显示我的代理设置?

通常是因为可以为全局 all 存储库添加代理设置.

Typically because a proxy setting could have been added for all repository, globally.

 git config --global --list

应位于〜/.gitconfig %USERPROFILE%\.gitconfig 中.

注意:如果要删除特定值(而不是正则表达式),请使用Git 2.30(Q1 2021)

Note: if you want to remove a specific value (not a regex), use Git 2.30 (Q1 2021)

" git config " ( man )需要 value_regex 来学习" -文字值 "选项,将 value_regex 选项作为文字字符串.

Various subcommands of "git config"(man) that takes value_regex learn the "--literal-value" option to take the value_regex option as a literal string.

请参见提交c902618 (2020年11月25日),由提交3f1bae1 fda4394 提交d156719 提交247e2f8 提交504ee12 (2020年11月25日)由 Junio C Hamano合并- gitster -提交a10e784 ,2020年12月8日)

See commit c902618 (25 Nov 2020) by Junio C Hamano (gitster).
See commit 3f1bae1, commit c90702a, commit fda4394, commit d156719, commit 2076dba, commit 247e2f8, commit 504ee12 (25 Nov 2020) by Derrick Stolee (derrickstolee).
(Merged by Junio C Hamano -- gitster -- in commit a10e784, 08 Dec 2020)

config :添加-固定值选项,未实现

签名人:Derrick Stolee

" git config '( man )内置的" value-pattern "参数用于多个操作.

The 'git config'(man) builtin takes a 'value-pattern' parameter for several actions.

当期望精确值匹配而不是正则表达式匹配时,这可能引起混乱,尤其是当输入字符串包含元字符时.虽然调用者可以自己转义模式,但允许参数禁用模式匹配以支持精确的字符串匹配会更友好.

This can cause confusion when expecting exact value matches instead of regex matches, especially when the input string contains metacharacters. While callers can escape the patterns themselves, it would be more friendly to allow an argument to disable the pattern matching in favor of an exact string match.

添加一个新的"-固定值"选项,该选项当前不会更改行为.

Add a new '--fixed-value' option that does not currently change the behavior.

以后将为每个适当的操作进行更改,以填充实现.现在,检查并测试-fixed-value 在包含不兼容操作或没有' value-pattern '参数时是否将中止命令.

The implementation will be filled in by later changes for each appropriate action. For now, check and test that --fixed-value will abort the command when included with an incompatible action or without a 'value-pattern' argument.

之所以选择名称"--fixed-value",是因为它除了简单的值外还选择了"--fixed"之类的简单命令.

The name '--fixed-value' was chosen over something simpler like '--fixed' because some commands allow regular expressions on the key in addition to the value.

git config 现在包含在手册页:

-固定值

value-pattern 参数一起使用时,将 value-pattern 视为确切的字符串而不是正则表达式.这将限制仅与值匹配的名称/值对完全等于 value-pattern .

--fixed-value

When used with the value-pattern argument, treat value-pattern as an exact string instead of a regular expression. This will restrict the name/value pairs that are matched to only those where the value is exactly equal to the value-pattern.

这篇关于Git:重置git配置文件的最简单方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆