【问题标题】:Can't Switch two users in GIT. Cannot change old GIT user using macOS无法在 GIT 中切换两个用户。无法使用 macOS 更改旧 GIT 用户
【发布时间】:2021-04-30 21:25:33
【问题描述】:

尝试使用我的两个 GIT 用户时,我感到非常生气。直到今天,我只有一个,但现在我创建了另一个,个人和工作资料。 我配置了两个不同的 ssh 密钥,并使用 ifs 条件修改了我的用户主文件夹中的.gitconfig,但没有任何改变...... 我尝试了一些事情(但没有任何效果):

  • 将全局用户更改为新用户。 (在~/.gitconfig)
  • 设置存储库用户(在/path/repository/.git/config)
  • 如果我家有条件.gitconfig
  • 更改 Visual Studio Code git 用户

我也尝试过git config --list --show-origin,但此列表结果中显示的每个文件的第一个用户已被删除。 返回列表:

file:/Applications/Xcode.app/Contents/Developer/usr/share/git-core/gitconfig    credential.helper=osxkeychain
file:/Users/elenitaex5/.gitconfig       push.default=current
file:/Users/elenitaex5/.gitconfig       pull.default=current
file:/Users/elenitaex5/.gitconfig       includeif.gitdir:~/projects/.path=~/projects/.gitconfig
file:/Users/elenitaex5/projects/.gitconfig      user.name=Elena
file:/Users/elenitaex5/projects/.gitconfig      user.email=elena.maXXXo@gmail.com
file:/Users/elenitaex5/.gitconfig       user.name=Elena
file:/Users/elenitaex5/.gitconfig       user.email=elena.maXXXo@gmail.com
file:.git/config        core.repositoryformatversion=0
file:.git/config        core.filemode=true
file:.git/config        core.bare=false
file:.git/config        core.logallrefupdates=true
file:.git/config        core.ignorecase=true
file:.git/config        core.precomposeunicode=true
file:.git/config        user.name=Elena
file:.git/config        user.email=elena.mXXXo@gmail.com
file:.git/config        remote.origin.url=git@github.com:elenitaex5/homeManager.git
file:.git/config        remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*

我在尝试 git push 时出错:

ERROR: Permission to elenitaex5/homeManager.git denied to elenaphone.
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

我也找不到...用户在任何文件中都以别名命名。 有人知道另一个 GIT 用户文件吗?或者可以保存在哪里?

我真正想做什么?

拥有两个不同的 git 用户并在我的个人项目中与我的个人用户进行提交,并使用工作 git 用户在工作项目中进行提交。

到目前为止,我只需要使用一个,但我现在需要两个。我已经尝试了一切以使第二个工作,甚至更改全局 git 用户,但没有任何工作。某处...有一个文件以第一个为优先级,我不知道在哪里...

【问题讨论】:

  • 您能否edit 更清楚地解释您想要实现的目标以及目前正在发生的事情?您是否希望能够在这两个用户之间切换,或者更改哪个用户出现在某个特定位置?在您提到的文件中准确显示您编辑的设置也会很有帮助。
  • 你的目标是什么?每次远程访问仓库时要输入 git-user 和密码吗?这样您就可以在两个帐户之间切换。
  • git commit 使用 user.name 和 user.email 设置进行提交。一旦提交,就不能更改任何提交(任何人或任何事,包括git push),并且用户设置完全不相关。 git push 操作使用第三方非 Git 软件进行身份验证(如果有的话)。此身份验证的工作方法取决于协议(例如 https 与 ssh)和操作系统以及帮助软件。所以你需要指定这些。
  • 看起来您正在使用 ssh 推送(基于 URL)并且在 macOS 上(基于 XCode 事物)。 macOS 倾向于使用钥匙串的东西。我不太确定如何按照您想要的方式进行操作。

标签: git github


【解决方案1】:

感谢@torek,我在这个问题中找到了解决方案:

Store keychain credentials for multiple github accounts

我尝试使用两个带有 ssh 密钥的 github 帐户,但在 MAC 中需要钥匙串。 因此,当一个存储库被克隆时,我们需要通过 HTTPS(包括用户)而不是像这样的 SSH:

git clone https://youruser@github.com/youruser/project.git

然后我尝试了 git push 和 IDE 询问我的密码并正确执行推送操作。

重要提示 从 2021 年 8 月起,Git 不再接受带密码的身份验证,HTTPS 登录将需要个人访问令牌。 GIT Deprecation announcement

您可以在此链接中创建新的个人令牌 Creating a personal access token

【讨论】:

    猜你喜欢
    • 2017-10-04
    • 2018-03-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-19
    • 2020-12-16
    • 2020-12-27
    • 1970-01-01
    相关资源
    最近更新 更多