在 Xcode 4 中,如何将远程 GitHub 存储库添加到现有的本地项目?
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“陷阱”。
- 从欢迎使用 Xcode 对话框中列出项目
- “连接到存储库”。
- 使用 GitHub SSH URL 作为位置
- 给它一个名称(RepositoryName)并克隆到目录
- 第一次尝试似乎失败,即使内容已下载
- 再试一次,它可以工作。
- 现在,在 Organizer 窗口中定义了一个新的存储库,其来源设置为 GitHub 远程 SSH URL。
- 在刚刚克隆到的目录中创建一个新项目,但不要勾选“为此项目创建本地 git 存储库”选项。
- 对本地 Git 存储库进行初始提交。
- 尝试源代码控制 ->推送和 Xcode 4 失败,并显示“由于对存储库 RepositoryName 的访问被拒绝,因此无法执行该操作。检查用户名和密码'
- 尝试源代码控制 -> Push 和 Xcode 4 再次弹出远程存储库对话框,但这次检测到一个名为 origin 的远程存储库。旁边有一个黄色球和“需要身份验证”。
- 再次单击“推送”会使远程推送生效。
我发现但尚未解决的一件事是,从 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.
- List item
- 'Connect to a repository' from Welcome to Xcode dialog.
- Use GitHub SSH URL for Location
- Give it a name (RepositoryName)and Clone to a directory
- 1st attempt appears to fail even though contents are downloaded
- Try Again and it works.
- There is now a new Repository defined in the Organizer window with its origin set to the GitHub remote SSH URL.
- Create a New Project within the directory you just cloned into but DO NOT tick the 'Create local git repository for this project' option.
- Do initial commit to local Git repository.
- 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'
- 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'.
- 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我想我找到了 Xcode 方式将现有项目推送到 GitHub 或任何其他远程存储库!
前提条件
将其推送到远程
在 Xcode 中打开组织器,然后转到 >Repositories 选项卡
首先单击Remotes > 然后单击“添加远程”
输入远程名称和位置 的远程存储库并单击“创建”
然后选择您的项目并打开
文件->源代码控制 ->推...
选择您的远程存储库并等待它可连接!在括号中查找创建。
现在您的旧项目已发布到 GitHub
我希望它也适合您!就我而言,它适用于每个远程 git 存储库。
如果有不清楚的地方或英语写得不好,请通过 twitter 与我联系!
I think I found the Xcode way to push a existing project to GitHub or any other remote repository!
Preconditions
Push it to remote
Open the Organizer in Xcode an go to the Repositories tab
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
Then select your project and open
File -> Source Control -> Push ...
Select your remote repository and wait until it is connectable! Look for the Create in the brackets.
Now your old project is published to 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!
我已经使用 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.Xcode 6.2(可能还有 6.x)改变了一切。管理器中不再有“存储库”选项卡。以下是如何使用较新的 Xcode 执行此操作。
要将具有本地 git 存储库的项目添加到 GitHub,您需要执行以下操作:
完毕。
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:
Done.