在 Xcode 中更改 Git 的用户名?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12335015/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 01:26:32  来源:igfitidea点击:

Change the username for Git in Xcode?

xcodegitgithubsettingsusername

提问by whoosy

Is there any way to change the Git username and email for Xcode? When I try commit now it will post my real name. I want it to post my GitHub username so that you can link commits to my user on GitHub.

有没有办法更改 Xcode 的 Git 用户名和电子邮件?当我现在尝试提交时,它会发布我的真实姓名。我希望它发布我的 GitHub 用户名,以便您可以将提交链接到我在 GitHub 上的用户。

Usually with Git I've been able to just type git config --global user.name whooshin the terminal but it doesn't seem to work on Mac and Xcode.

通常使用 Git 我已经能够git config --global user.name whoosh在终端中输入,但它似乎不适用于 Mac 和 Xcode。

采纳答案by VonC

As mentioned in "Where is the Git commit info set in Xcode 4?", XCode takes user information from your contact cardfrom your (2012) Address Book(called Contact in 2014).

正如“在 Xcode 4 中设置的 Git 提交信息哪里?”中所述,XCode从您的(2012 年)地址簿在 2014 年称为 Contact)中获取您的联系人卡片中的用户信息。

Changing your contact card would change user information (for newcommits)

更改您的联系人卡片会更改用户信息(对于提交)



Update 2014 (2 years later), as illustrated in sergtk's answer, XCode (5+) now supports the git config user.nameand user.email.
That will fill out:

2014 年更新(2 年后),如sergtk回答所示,XCode (5+)现在支持 git configuser.nameuser.email.
这将填写:

XCode user.name/user.email

XCode 用户名/用户.email

Using xcrunbefore the git configcommands allows to locate or invoke coexistence- and platform-aware developer tools from the command-line.
(assuming the Xcode Command-line Tools is up-to-date)

xcrungit config命令之前使用允许从命令行定位或调用共存和平台感知开发人员工具。
(假设Xcode 命令行工具是最新的

回答by sergtk

The following terminal commands works for me:

以下终端命令对我有用:

xcrun git config --global user.name 'new_user_name'
xcrun git config --global user.email '[email protected]'

These are to update user name and e-mail respectively.

这些是分别更新用户名和电子邮件。

After execution of that commands successive commits to Git via Xcode will use the data specified in it.

执行该命令后,通过 Xcode 连续提交到 Git 将使用其中指定的数据。

回答by Greeso

Since I have multiple projects with different commit names, the solution provided by @sergtk does not work for me. Instead, I did the following:

由于我有多个具有不同提交名称的项目,@sergtk 提供的解决方案对我不起作用。相反,我做了以下事情:

xcrun git config --local user.name 'new_user_name'
xcrun git config --local user.email '[email protected]'

Also, note that the first commit needs to be changed, so I used the solution provided here to fix this: Change the author and committer name and e-mail of multiple commits in Git

另外,请注意第一次提交需要更改,所以我使用了这里提供的解决方案来解决这个问题:Change the author and committer name and e-mail of multiple commits in Git

回答by Hot'n'Young

I start working from corporate mac and had the same problem with bitbacket repository. Any answers didn't help me. Neither removing previous user from address book and saving my own nor terminal commands. One day I tried to work with new repo from SourceTree (free soft from Atlassian). I have replaced user name and mail with my own in preferences and all was ok. I had commits with my own credentials. Ye! I hope my solving will be useful!

我从公司 mac 开始工作,并且在 bitbacket 存储库中遇到了同样的问题。任何答案都没有帮助我。既不从地址簿中删除以前的用户,也不保存我自己的或终端命令。有一天,我尝试使用 SourceTree 的新存储库(来自 Atlassian 的免费软件)。我在首选项中用我自己的用户名和邮件替换了用户名和邮件,一切正常。我使用自己的凭据进行了提交。耶!我希望我的解决方法有用!