在 Xcode 4 中,如何将远程 GitHub 存储库添加到现有的本地项目?

发布于 2024-11-03 18:18:11 字数 2364 浏览 2 评论 0原文

Xcode 4 中的 Git 集成非常受欢迎,但在处理远程存储库时似乎有点不稳定。 为了清楚起见,我使用 OS X 版本 10.6.7 和 Xcode 4.0.2 (4A2002a)。

如果我创建一个新的 Xcode 4 项目并接受创建本地 Git 存储库的选项,那么一切都很好。我可以在本地进行承诺,这很棒。

当我想将新项目推送到 GitHub 时,我想添加一个远程存储库并将本地更改推送到 GitHub。我可以将 GitHub 存储库添加到 Xcode 4 作为“管理器”窗口中的新存储库,但无法将其设置为我现有项目的远程存储库。

所以我转而在终端中使用 git 命令。

git remote add origin https://<username>@github.com/<organization>/<repository>.git

如果我然后返回 Xcode 4 并尝试使用

文件->源代码控制 ->推...

然后出现选择要将更改推送到的存储库。对话框,其中列出了远程存储库。有一个黄色指示器表示需要身份验证,这很好,因为我还无法输入 HTTPS 凭据。 但是,当我单击“推送”并尝试推送更改时,它显示“无法执行该操作,因为对存储库“来源”的访问被拒绝。”

然后会出现一个对话框,提示我输入用户名和密码,其中包含我预先填写的内容,因此它必须从本地存储库的配置中正确读取此信息。

当我输入密码时,Xcode 4 崩溃并出现以下错误

ASSERTION FAILURE in /SourceCache/IDEKit/IDEKit-303/Framework/Classes/SourceControl/IDESourceControlOperationInfo.m:59
Details:  Message sent to invalidated object: <IDESourceControlPushOperationInfo, 0x200bd2a80>. Backtrace for invalidation:
 (null)
Object:   <IDESourceControlPushOperationInfo: 0x200bd2a80>
Method:   -invalidate
Thread:   <NSThread: 0x200020700>{name = (null), num = 1}
Hints:   None

如果我重新启动 Xcode,则 origin 存储库已添加到 Organizer 中的存储库浏览器中,我可以在 GitHub 上看到 master 分支,因此我知道凭据无需我改变任何东西都是对的。

有没有人找到一种可靠的方法,首先从本地项目开始,将 Xcode 4 与 GitHub 结合使用?

如果我克隆一个包含 Xcode 项目的现有 GitHub 存储库,用 Xcode 4 打开它,那么即使第一次推送似乎失败了,第二次推送也可以工作。因此,也许用 Xcode 4 从头开始​​为我创建存储库并不是最好的模式(直到他们在更高版本的 Xcode 4 中改进 Git 工具)。

编辑一个解决方案的更多详细信息

此示例仅真正适用于您要添加到 GitHub 存储库的第一个项目。因此,我认为您最好执行以下步骤,并记住此解决方案中似乎仍然存在一些 Xcode“陷阱”。

  1. 从欢迎使用 Xcode 对话框中列出项目
  2. “连接到存储库”。
  3. 使用 GitHub SSH URL 作为位置
  4. 给它一个名称(RepositoryName)并克隆到目录
  5. 第一次尝试似乎失败,即使内容已下载
  6. 再试一次,它可以工作。
  7. 现在,在 Organizer 窗口中定义了一个新的存储库,其来源设置为 GitHub 远程 SSH URL。
  8. 在刚刚克隆到的目录中创建一个新项目,但不要勾选“为此项目创建本地 git 存储库”选项。
  9. 对本地 Git 存储库进行初始提交。
  10. 尝试源代码控制 ->推送和 Xcode 4 失败,并显示“由于对存储库 RepositoryName 的访问被拒绝,因此无法执行该操作。检查用户名和密码'
  11. 尝试源代码控制 -> Push 和 Xcode 4 再次弹出远程存储库对话框,但这次检测到一个名为 origin 的远程存储库。旁边有一个黄色球和“需要身份验证”。
  12. 再次单击“推送”会使远程推送生效。

我发现但尚未解决的一件事是,从 GitHub 返回的响应消息以及签入哈希值和任何消息似乎都会在 Xcode 日志导航器中报告为推送失败,即使推送是成功的GitHub 很关心。

还有其他人有更好的解决方案吗?

The Git integration in Xcode 4 is very welcome however it seems to be a bit flaky when it comes to dealing with remote repositories.
For clarity I'm using OS X version 10.6.7 and Xcode 4.0.2 (4A2002a).

If I create a new Xcode 4 Project and accept the option to create a local Git repository, all is well. I can commit locally and that's great.

When I want to push the new project to GitHub I want to add a remote repository and push my local changes up to GitHub. I can add a GitHub repository to Xcode 4 as a new Repository in the Organizer window but there's no method of setting it as a remote repository for my existing project.

So I switch to using git commands in Terminal.

git remote add origin https://<username>@github.com/<organization>/<repository>.git

If I then go back to Xcode 4 and try to use

File -> Source Control -> Push...

then the Choose the repository to which to push changes. dialog appears listing the origin remote repository. There's a yellow indicator saying that Authentication is required, which is fine as I've not been able to enter my credentials yet for HTTPS.
However when I click 'Push' and it tries to push the changes it says "The operation could not be performed because access to the repository 'origin' is denied."

A dialog prompting me for my username and password then appears with my pre-filled out so it must be reading this correctly from the local repository's config.

When I enter my password Xcode 4 then crashes with the following error

ASSERTION FAILURE in /SourceCache/IDEKit/IDEKit-303/Framework/Classes/SourceControl/IDESourceControlOperationInfo.m:59
Details:  Message sent to invalidated object: <IDESourceControlPushOperationInfo, 0x200bd2a80>. Backtrace for invalidation:
 (null)
Object:   <IDESourceControlPushOperationInfo: 0x200bd2a80>
Method:   -invalidate
Thread:   <NSThread: 0x200020700>{name = (null), num = 1}
Hints:   None

If I restart Xcode an origin repository has been added to the Repositories browser in Organizer and I can see the master branch on GitHub so I know the credentials are right without me changing anything.

Has anyone found a reliable way of using Xcode 4 with GitHub starting with a local project first?

If I clone an existing GitHub repository with an Xcode project in it, open it with Xcode 4 then even though the first Push seems to fail, the 2nd push did then work. So maybe starting from absolute scratch with Xcode 4 creating the repository for me isn't the best pattern (until they improve the Git tooling in a later version of Xcode 4).

EDIT WITH FURTHER DETAILS OF ONE WORKAROUND

This example only really applies to the first project you're adding to a GitHub repository. As such I think you're better off with the following steps, bearing in mind there still seem to be some Xcode 'gotchas' in this solution.

  1. List item
  2. 'Connect to a repository' from Welcome to Xcode dialog.
  3. Use GitHub SSH URL for Location
  4. Give it a name (RepositoryName)and Clone to a directory
  5. 1st attempt appears to fail even though contents are downloaded
  6. Try Again and it works.
  7. There is now a new Repository defined in the Organizer window with its origin set to the GitHub remote SSH URL.
  8. Create a New Project within the directory you just cloned into but DO NOT tick the 'Create local git repository for this project' option.
  9. Do initial commit to local Git repository.
  10. Try Source Control -> Push and Xcode 4 fails with 'The operation could not be performed because access to the repository RepositoryName was denied. Check username and password'
  11. Try Source Control -> Push and Xcode 4 pops up the remote Repository dialog again but this time has detected a remote Repository called origin. Next to it there's a yellow ball and 'Authentication required'.
  12. Clicking 'Push' again caused the remote Push to work.

One thing I've spotted and not managed to work out yet is that the response messages back from GitHub with the checkin hash value and any messages seem to get reported in Xcode Log navigator as Push failures, even though the Push is successful as far as GitHub is concerned.

Anyone else have a better solution?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

南笙 2024-11-10 18:18:11

我想我找到了 Xcode 方式将现有项目推送到 GitHub 或任何其他远程存储库!

前提条件

  • 我假设您有一个由 Xcode 4 创建的项目带有本地 git 存储库。
  • 您创建了一个空的远程 git 存储库(在下面的示例中我将其称为RemoteRepository

将其推送到远程

  1. 在 Xcode 中打开组织器,然后转到 >Repositories 选项卡

  2. 首先单击Remotes > 然后单击“添加远程”

    Xcode Organizer

  3. 输入远程名称位置 的远程存储库并单击“创建”

    添加远程对话框

  4. 然后选择您的项目并打开文件->源代码控制 ->推...

    打开推送对话框

  5. 选择您的远程存储库并等待它可连接!在括号中查找创建

    推送对话框

  6. 现在您的旧项目已发布到 GitHub

    result on GitHub

我希望它也适合您!就我而言,它适用于每个远程 git 存储库

如果有不清楚的地方或英语写得不好,请通过 twitter 与我联系!

I think I found the Xcode way to push a existing project to GitHub or any other remote repository!

Preconditions

  • I assume that you have a project created by Xcode 4 with a local git repository.
  • You created an empty remote git repository (I call it RemoteRepository in in the following example)

Push it to remote

  1. Open the Organizer in Xcode an go to the Repositories tab

  2. At first click on Remotes and then on "Add Remote"

    Xcode Organizer

  3. Enter a Remote Name and the Location of your remote repository and click on create

    Add a remote dialog

  4. Then select your project and open File -> Source Control -> Push ...

    open push dialog

  5. Select your remote repository and wait until it is connectable! Look for the Create in the brackets.

    push dialog

  6. Now your old project is published to GitHub

    result on GitHub

I hope it will works for you also! In my case it works with every remote git repository.

Please contact me on twitter if something unclear or wrote in bad English!

〆一缕阳光ご 2024-11-10 18:18:11

我已经使用 ssh 连接成功完成了此操作(看起来像 [电子邮件受保护]:<用户名>/<项目>.git)。它根据 SSH 公钥对用户进行身份验证,您可以在命令行上生成该公钥——github 上的“帮助”部分有很多相关文档。

I've done this successfully using an ssh connection (which looks like [email protected]:<username>/<project>.git). It authenticates the user based on an SSH public key, which you can generate on the command line--lots of docs about that at github in the "help" section.

白首有我共你 2024-11-10 18:18:11

Xcode 6.2(可能还有 6.x)改变了一切。管理器中不再有“存储库”选项卡。以下是如何使用较新的 Xcode 执行此操作。

要将具有本地 git 存储库的项目添加到 GitHub,您需要执行以下操作:

  1. 转到“源代码管理”菜单,选择您的项目并选择“配置”:

在此处输入图像描述

  1. 您将看到:

在此处输入图像描述

  1. 选择“遥控器”选项卡,然后按左下角的“+”。选择添加远程。

在此处输入图像描述

  1. 输入远程存储库的名称,然后输入远程存储库的 URL。确保您已经创建了此远程存储库,如果在 GitHub 上,请指定这是一个现有项目,而不是新项目。

在此处输入图像描述

  1. 您即将完成。转至源代码管理菜单并选择推送。然后,您将看到上一步中使用的存储库的名称,例如“simplest/master”;按下按钮。

完毕。

Xcode 6.2 (and possibly 6.x) changed things around. There no longer is a Repositories tab in the Organizer. Here's how to do it with the newer Xcodes.

To add a project with a local git repository to GitHub, this is what you do:

  1. Go to the Source Control menu, elect your project and select Configure:

enter image description here

  1. You'll see:

enter image description here

  1. Select the Remotes tab, and press the "+" in the lower left corner. Select Add Remote.

enter image description here

  1. Type in a name for the remote repository, and type in the URL for your remote repository. Make sure you've created this remote repository already, and if on GitHub, make are you specify that this is an existing project, and not a new one.

enter image description here

  1. You're almost done. Go to the Source Control menu and select Push. You will then see the name of the repo you used in the last step, something like "simplest/master"; press the Push button.

Done.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文