Bitbucket + XCode 4.2 + Git

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8131692/
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-09 04:10:09  来源:igfitidea点击:

Bitbucket + XCode 4.2 + Git

xcodegitxcode4.2bitbucket

提问by raul782

I've been looking for a solution with Bitbucket and XCode.

我一直在寻找 Bitbucket 和 XCode 的解决方案。

As everybody knows, XCode 4.2 comes with git support. I've created a bitbucket account and I wanted to push my changes to my repository,

众所周知,XCode 4.2 自带 git 支持。我创建了一个 bitbucket 帐户,我想将我的更改推送到我的存储库,

I've followed this tutorial https://confluence.atlassian.com/display/BITBUCKET/Use+the+SSH+protocol+with+Bitbucket

我已经按照本教程 https://confluence.atlassian.com/display/BITBUCKET/Use+the+SSH+protocol+with+Bitbucket

However this is the problem I'm facing. When I'm in the Organizer - Repositories Section at XCode, I go to my remotes folder and create a repository.

然而,这是我面临的问题。当我在 XCode 的 Organizer - Repositories 部分时,我会转到我的 remotes 文件夹并创建一个存储库。

ssh://[email protected]/username/myrepo.git

ssh://[email protected]/username/myrepo.git

However when I'm asked for Name and password, the ones I provide as username and password fails. I've also tried with git as a user but no luck.

但是,当我被要求输入名称和密码时,我提供的用户名和密码失败。我也试过用 git 作为用户,但没有运气。

UPDATE:

更新:

I've created a ~/.ssh/config file where I've added a specific configuration for bitbucket.

我创建了一个 ~/.ssh/config 文件,我在其中添加了 bitbucket 的特定配置。

Host bitbucket.org
HostName bitbucket.org
IdentityFile ~/.ssh/bitbucket
User username

I've tested it with ssh -T [email protected] and It works, it gets authenticated.

我已经使用 ssh -T [email protected] 对其进行了测试,它可以正常工作,并且已通过身份验证。

However, when I test this with XCode I got the following error. "Authentication failed because the name or password was incorrect."

但是,当我使用 XCode 进行测试时,出现以下错误。“由于名称或密码不正确,身份验证失败。”

I know I'm missing something here.

我知道我在这里遗漏了一些东西。

UPDATE 2:

更新 2:

I've managed to solve the issue but only from command line, not from XCode. I'll post my solution later but feel free if you have a way to do it from XCode

我设法解决了这个问题,但只能从命令行,而不是从 XCode。我稍后会发布我的解决方案,但如果您有办法从 XCode 中做到这一点,请随意

Thanks

谢谢

回答by trolley

It worked for me by using the HTTPS URI, but I needed to remove my user name from it. For example change:

它通过使用 HTTPS URI 对我有用,但我需要从中删除我的用户名。例如改变:

https://[email protected]/username/myrepo.git

https://[email protected]/username/myrepo.git

to

https://bitbucket.org/username/myrepo.git

https://bitbucket.org/username/myrepo.git

then supply your username and password when prompted.

然后在提示时提供您的用户名和密码。

回答by Gil Margolin

Removing the username did not work for me. But I was able to solve the issue by adding my password like this to the URL:

删除用户名对我不起作用。但是我能够通过将这样的密码添加到 URL 来解决这个问题:

https://username:[email protected]/username/myrepo.git

https://username:[email protected]/username/myrepo.git

回答by Simon

I was able to use the XCode UI by using the https URL and entering my bitbucket username and password when prompted.

我能够通过使用 https URL 并在提示时输入我的 bitbucket 用户名和密码来使用 XCode UI。

回答by serge-k

iOS 9.2, Xcode 7.2, ARC enabled

iOS 9.2、Xcode 7.2、ARC 已启用

It seems that every time I start a new Xcode project, I have to crawl back to this post and others like it to put together a solution to get my *.git repository set up for the new project. My goal with this answer is to update and compile a full solution. Thanks to all original contributors, especially "trolley".

似乎每次我开始一个新的 Xcode 项目时,我都必须爬回这篇文章和其他喜欢它的人来整理一个解决方案,以便为新项目设置我的 *.git 存储库。我对这个答案的目标是更新和编译一个完整的解决方案。感谢所有原始贡献者,尤其是“手推车”。

For a very thorough description, please refer to this link: http://www.appcoda.com/git-source-control-in-xcode/

有关非常详尽的描述,请参阅此链接:http: //www.appcoda.com/git-source-control-in-xcode/

1. Create your new Xcode project as usual, but make sure that you enable source control, see below:

1. 像往常一样创建新的 Xcode 项目,但请确保启用源代码控制,见下文:

If you didn't do this, then go here to see how to do it once the project is already created: https://stackoverflow.com/a/17790306/4018041

如果你没有这样做,那么一旦项目已经创建,去这里看看如何做:https: //stackoverflow.com/a/17790306/4018041

Enable source control when creating your project.

创建项目时启用源代码控制。

2. From the top tool bar select Source Control->"current branch"->Configure "your project name", see below:

2.从顶部工具栏选择Source Control->“当前分支”->配置“您的项目名称”,如下图:

Configure the source control

配置源代码管理

3. Choose Remotes from the configure menu tab, hit the "+" sign and select "Add Remote", see below:

3. 从配置菜单选项卡中选择遥控器,点击“+”号并选择“添加遥控器”,如下所示:

Add remote source

添加远程源

4. You will be prompted to enter the repository name and enter the address for the repository, see below:

4. 系统将提示您输入存储库名称并输入存储库地址,如下所示:

Here you would use the instructions "trolley" provided here: https://stackoverflow.com/a/9271409/4018041

在这里,您将使用此处提供的“手推车”说明:https: //stackoverflow.com/a/9271409/4018041

https://bitbucket.org/username/myrepo.git

In the above example, "myrepo" is the name of the repository at bitbucket.org; but locally you can assign any name you want, the default name being "origin" as you see in the picture below.

在上面的示例中,“myrepo”是 bitbucket.org 中存储库的名称;但在本地您可以指定任何您想要的名称,默认名称为“origin”,如下图所示。

Enter a repository name and address

Enter a repository name and address

5. Enter the username and password that you use to access your bitbucket.org account, see below:

5. 输入您用来访问您的 bitbucket.org 帐户的用户名和密码,如下所示:

Your user name is most likely the e-mail you used to register.

您的用户名很可能是您用来注册的电子邮件。

Credentials for the repository

Credentials for the repository

6. After pressing OK and if the credentials were accepted, then you should get a green check mark message. That is it!

6. 按 OK 后,如果凭据被接受,那么您应该会收到一条绿色复选标记消息。这就对了!

After this you are able to Source Control->Push your local *.git to your bitbucket.org repository, which is named locally as "origin" (default).

在此之后,您可以源代码控制-> 将您的本地 *.git 推送到您的 bitbucket.org 存储库,该存储库在本地命名为“origin”(默认)。

Push local *.git repository to origin

Push local *.git repository to origin

A similar text with a green check mark will appear upon successful push up to the bitbucket.org repository.

成功推送到 bitbucket.org 存储库后,将出现带有绿色复选标记的类似文本。

Note: Make sure you commit an initial change for the project in order for your local *.git to get properly created.

注意:确保为项目提交初始更改,以便正确创建本地 *.git。

Hope this helps someone. Cheers!

希望这可以帮助某人。干杯!

回答by Ben Lachman

Here is an attempt at a full answer…

这是一个完整答案的尝试......

Create a bitbucket key if you haven't using ssh-keygen. Pick a decent name, something like bitbucket_rsaassuming you create an rsa key. Put it in ~/.ssh/.

如果您没有使用ssh-keygen. 选择一个合适的名称,例如bitbucket_rsa假设您创建了一个 rsa 密钥。把它放进去~/.ssh/

Once this is created, add:

创建完成后,添加:

Host bitbucket.org  
HostName bitbucket.org  
IdentityFile ~/.ssh/<bitbucket key filename above>

to your ~/.ssh/config.

到您的 ~/.ssh/config。

Next, add this key to the Bitbucket web interface using the Manage Account > SSH Keystool. To get the publickey onto your clipboard use:

接下来,使用该Manage Account > SSH Keys工具将此密钥添加到 Bitbucket Web 界面。要获得公共密钥到剪贴板上使用:

$ pbcopy < ~/.ssh/<bitbucket key filename above>.pub

Finally, make sure you're using the ssh address provided by Bitbucket vs the https one. These look like:

最后,确保您使用的是 Bitbucket 提供的 ssh 地址,而不是 https 地址。这些看起来像:

[email protected]:accountname/repositoryname.git

and can be accessed by the drop down labeled HTTPS (currently in the right side bar).

并且可以通过标记为 HTTPS 的下拉菜单访问(当前在右侧栏中)。

Xcode (including Xcode 5) should now work, as will git from the command line.

Xcode(包括 Xcode 5)现在应该可以工作了,命令行中的 git 也是如此。

回答by Mad Hacker

You can solve this problem in XCode without going to command line. You had everything right in your question but you set the URL up wrong.

您可以在 XCode 中解决此问题,而无需转到命令行。您在问题中的所有内容都正确,但您设置的 URL 错误。

It should be: [email protected]:username/myrepo.git

它应该是:[email protected]:username/myrepo.git

Instead of what you had: ssh://[email protected]/username/myrepo.git

而不是你所拥有的:ssh://[email protected]/username/myrepo.git

回答by Finn Gaida

I know there already are several answers, but I couldn't seem to get it working for me until one hour, so maybe I'm helping out someone out there.

我知道已经有几个答案,但我似乎在一小时内才能让它对我来说有效,所以也许我正在帮助那里的某个人。

My solution was simply to add my username to https://bitbucket.org/USERNAME/PROJECT_NAME/admin/accessas an admin so then I could just normally type into Xcode as URL https://[email protected]/USERNAME/PROJECT_NAME.gitwith my username and password.

我的解决方案只是将我的用户名添加https://bitbucket.org/USERNAME/PROJECT_NAME/admin/access为管理员,这样我就可以正常地将https://[email protected]/USERNAME/PROJECT_NAME.git我的用户名和密码作为 URL 输入到 Xcode 中。

IMPORTANT: USERNAME stands for the user HOSTING the project, so if you're working on the repo of your colleague, this will be his username.

重要提示:USERNAME 代表主持项目的用户,所以如果你正在处理你同事的 repo,这将是他的用户名。

Hope this helps.

希望这可以帮助。

回答by Steven Lu

I was able to get XCode to accept and use my SSH key I had previously set up with Bitbucket by specifying git as the username (in the XCode UI), and putting my password, and my Bitbucket username goes in the URL of the repo.

通过将 git 指定为用户名(在 XCode UI 中)并输入我的密码,我能够让 XCode 接受并使用我之前在 Bitbucket 上设置的 SSH 密钥,并将我的密码和我的 Bitbucket 用户名放在 repo 的 URL 中。

Had to mess around with it a few times before it started working.

在它开始工作之前不得不弄乱它几次。

回答by Blender

You have to add your generated SSH key to your account.

您必须将生成的 SSH 密钥添加到您的帐户。

I use GitHub, but BitBucket is basically a clone of it so the same procedures apply:

我使用 GitHub,但 BitBucket 基本上是它的克隆,因此应用相同的程序:

cat ~/.ssh/id_rsa.pub | pbcopy

Now try re-connecting.

现在尝试重新连接。

回答by raul782

Ok It looks like I couldn't make it through the XCode Client.

好的 看起来我无法通过 XCode 客户端。

However, the command line is the only way I managed to push my changes, and XCode only helped me to set the remote repository and add the credentials.

但是,命令行是我设法推送更改的唯一方法,而 XCode 仅帮助我设置远程存储库并添加凭据。

Finally what I've just needed to do is :

最后我只需要做的是:

$git push myrepo master

And I got a success message:

我收到一条成功消息:

Counting objects: 7, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (4/4), 360 bytes, done.
Total 4 (delta 3), reused 0 (delta 0)
remote: bb/acl: username is allowed. accepted payload.
To ssh://[email protected]/username/myrepo.git
 123abcd..5a12a67  master -> master