在 Xcode 4 中,如何将远程 GitHub 存储库添加到现有的本地项目? [英] In Xcode 4 how do I add a remote GitHub repository to an existing local project?

查看:26
本文介绍了在 Xcode 4 中,如何将远程 GitHub 存储库添加到现有的本地项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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).

如果我创建一个新的 Xcode 4 项目并接受创建本地 Git 存储库的选项,一切都很好.我可以在本地提交,这很棒.

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.

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

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.

所以我切换到在终端中使用 git 命令.

So I switch to using git commands in Terminal.

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

如果我再回到 Xcode 4 并尝试使用

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

文件 -> 源代码管理 -> 推送...

File -> Source Control -> Push...

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

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.

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

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

如果我重新启动 Xcode,一个 origin 存储库已添加到 Organizer 的存储库浏览器中,并且我可以在 GitHub 上看到 master 分支,因此我无需更改任何内容就知道凭据是正确的.

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.

有没有人先从本地项目开始,找到一种在 GitHub 上使用 Xcode 4 的可靠方法?

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

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

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).

此示例仅适用于您添加到 GitHub 存储库的第一个项目.因此,我认为您最好执行以下步骤,请记住,此解决方案中似乎仍然存在一些 Xcode问题".

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. 列表项
  2. 欢迎使用 Xcode"对话框中的连接到存储库".
  3. 使用 GitHub SSH URL 作为位置
  4. 为其命名(RepositoryName)并克隆到目录
  5. 即使下载了内容,第一次尝试似乎也失败了
  6. 再试一次,效果很好.
  7. 现在在 Organizer 窗口中定义了一个新的存储库,其来源设置为 GitHub 远程 SSH URL.
  8. 在您刚刚克隆到的目录中创建一个新项目,但不要勾选为此项目创建本地 git 存储库"选项.
  9. 对本地 Git 存储库进行初始提交.
  10. 尝试源代码管理 -> 推送和 Xcode 4 失败并显示操作无法执行,因为对存储库的访问 RepositoryName 被拒绝.检查用户名和密码'
  11. Try Source Control -> Push 和 Xcode 4 再次弹出远程存储库对话框,但这次检测到一个名为 origin 的远程存储库.旁边有一个黄色的球和需要身份验证".
  12. 再次单击推送"会导致远程推送工作.
  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.

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

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?

推荐答案

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

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

  • 我假设您有一个由 Xcode 4 创建的项目,带有本地 git 存储库.
  • 您创建了一个空的远程 git 存储库(在以下示例中我将其称为 RemoteRepository)
  • 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)
  1. 在 Xcode 中打开 Organizer 并转到 Repositories 标签

首先点击遥控器,然后点击添加遥控器"

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

输入远程名称和远程存储库的位置,然后点击创建

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

然后选择你的项目并打开File ->源代码管理 ->推...

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

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

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

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

Now your old project is published to GitHub

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

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

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

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

这篇关于在 Xcode 4 中,如何将远程 GitHub 存储库添加到现有的本地项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆