【问题标题】:git config for specific local repository did not work特定本地存储库的 git config 不起作用
【发布时间】:2021-01-19 08:00:18
【问题描述】:

我的开发环境:

PS D:\github\jqxwidgets> git --version
git version 2.30.0.windows.1

Windows 10 x64 版本 2004。我的存储库https://github.com/donhuvy/jqxwidgets(仅用于学习 jQuery 插件框架)。在我的 PC 中有 Github Desktop for Windows,但我将它用于其他项目。

(1) 我尝试配置本地 git 存储库

git config user.name "Do Nhu Vy"
git config user.email "donhuvy@outlook.com"

没用。

(2) 我尝试了本地 git 存储库的配置

git config user.name "Do Nhu Vy"
git config user.email donhuvy@outlook.com

没用。

(3) 我尝试使用 Windows PowerShell(管理员)

git config user.name "Do Nhu Vy"
git config user.email "donhuvy@outlook.com"

没用。

我不想使用git config --global ...,因为在我的电脑上有很多项目有不同的远程服务器和不同的用户。

Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.

Try the new cross-platform PowerShell https://aka.ms/pscore6

PS C:\WINDOWS\system32> cd d:
PS D:\> cd .\github\
PS D:\github> cd .\jqxwidgets\
PS D:\github\jqxwidgets> ls


    Directory: D:\github\jqxwidgets


Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
d-----         1/19/2021   2:48 PM                .idea
d-----         1/19/2021   2:41 PM                jqxGrid
-a----         1/19/2021   2:39 PM           1714 .gitignore
-a----         1/19/2021   2:39 PM           1544 LICENSE
-a----         1/19/2021   2:39 PM             12 README.md


PS D:\github\jqxwidgets> git config user.name "Do Nhu Vy"
PS D:\github\jqxwidgets> git config --list
diff.astextplain.textconv=astextplain
filter.lfs.clean=git-lfs clean -- %f
filter.lfs.smudge=git-lfs smudge -- %f
filter.lfs.process=git-lfs filter-process
filter.lfs.required=true
http.sslbackend=schannel
core.autocrlf=true
core.fscache=true
core.symlinks=true
pull.rebase=false
credential.helper=manager-core
credential.https://dev.azure.com.usehttppath=true
init.defaultbranch=main
user.name=vyolbius
user.email=74403808+vyolbius@users.noreply.github.com
filter.lfs.clean=git-lfs clean -- %f
filter.lfs.smudge=git-lfs smudge -- %f
filter.lfs.process=git-lfs filter-process
filter.lfs.required=true
core.repositoryformatversion=0
core.filemode=false
core.bare=false
core.logallrefupdates=true
core.symlinks=false
core.ignorecase=true
remote.origin.url=https://github.com/donhuvy/jqxwidgets.git
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
branch.main.remote=origin
branch.main.merge=refs/heads/main
user.email=donhuvy@hotmail.com
user.name=Do Nhu Vy
PS D:\github\jqxwidgets>
PS D:\github\jqxwidgets>
PS D:\github\jqxwidgets> git --version
git version 2.30.0.windows.1
PS D:\github\jqxwidgets>
PS D:\github\jqxwidgets>

如何解决?

【问题讨论】:

    标签: git github


    【解决方案1】:

    本地配置将覆盖任何全局配置。
    检查你的:

    cd /path/to/my/repo
    git config --show-origin --show-scope -l
    

    尝试进行新的提交:应该使用正确的用户名/电子邮件进行创作。

    我总是使用(如documented here):

    git config --global user.useConfigOnly true
    

    这样,我不得不在每个新的本地 Git 存储库上设置正确的 user.name/email。

    【讨论】:

    【解决方案2】:

    它没有坏。

    PS D:\github\jqxwidgets> git config --list
    [snippage]
    user.name=vyolbius
    [snippage]
    user.name=Do Nhu Vy
    

    第一个值来自“更高”或“更全局级别”/不太适用的设置,第二个值来自“更本地级别”/更适用的设置。第二个值覆盖第一个值。

    (有一些 Git 设置是累积的。对于这些,您必须检查git config --listgit config --get-all 列出的所有值。但user.nameuser.email 不是累积的;它们是最后一个-列出-获胜。)

    【讨论】:

      【解决方案3】:

      你试过git config --local吗?此外,全局设置不会覆盖所有其他项目,而是会创建一个默认配置,除非本地设置不同。

      所以如果你设置你的全球邮箱

      git config --global user.email "donhuvy@outlook.com"
      

      这只会影响未在本地设置电子邮件的存储库。要在本地设置电子邮件

      git config --local user.email "donhuvy@outlook.com"
      

      全局和本地标志适用于所有人,并且对于所有设置都是必需的。

      【讨论】:

      猜你喜欢
      • 2019-12-07
      • 2023-04-06
      • 2017-11-15
      • 2023-03-20
      • 1970-01-01
      • 2012-03-19
      • 2011-03-12
      • 2014-09-06
      • 2020-07-23
      相关资源
      最近更新 更多