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

查看:196
本文介绍了在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然后崩溃,出现以下错误:/ b

  / SourceCache / IDEKit / IDEKit-303 / Framework中的ASSERTION FAILURE /类/ SourceControl / IDESourceControlOperationInfo.m:59 
详细信息:发送到无效对象的消息:< IDESourceControlPushOperationInfo,0x200bd2a80> ;. Backtrace for invalidation:
(null)
Object:< IDESourceControlPushOperationInfo:0x200bd2a80>
方法:-invalidate
线程:< NSThread:0x200020700> {name =(null),num = 1}
提示:无

如果我重新启动XCode,则 origin 存储库已添加到Organizer中的存储库浏览器中,我可以在GitHub上看到主分支



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



如果我使用XCode 4克隆现有的GitHub存储库,并使用XCode 4打开它,那么即使第一个Push似乎失败,第二次推送也会起作用。所以,也许从XCode 4开始从头开始创建存储库对我来说并不是最好的模式(直到他们改进了XCode 4更高版本中的Git工具)。



编辑一个替代方法的更多细节

这个例子只适用于您添加到GitHub存储库的第一个项目。因此,我认为您最好采用以下步骤,同时铭记这种解决方案似乎还存在一些XCode'陷阱'。


  1. 列出项目

  2. 从欢迎使用XCode对话框中连接到资料库。

  3. 使用GitHub SSH位址

  4. 为其命名( RepositoryName )并克隆到目录

  5. 即使内容已下载,第一次尝试仍然失败

  6. 重试并运行。

  7. 现在在Organizer窗口中定义了一个新的Repository,其源地址设置为GitHub远程SSH URL。

  8. 在刚刚克隆的目录中创建一个新项目,但不要勾选'为此项目创建本地git存储库'选项。

  9. 初始提交到本地Git仓库。

  10. 尝试源代码管理 - > Push和XCode 4失败,因为无法执行操作,因为访问存储库 RepositoryName wa否认。检查用户名和密码'

  11. 尝试源代码管理 - > Push和XCode 4再次弹出远程存储库对话框,但是这次检测到名为 origin 的远程存储库。在它旁边,有一个黄色的球和需要验证。
  12. 再次点击推送导致远程推送工作。
    $ b

    我发现的一件事并没有设法解决,就是GitHub的checkin hash值和任何消息的响应消息似乎都在XCode Log导航器中报告为Push失败,即使Push对GitHub而言也是成功的。



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

    解决方案

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

    先决条件




    • 我假设您有一个由Xcode 4创建的项目<

    • 您创建了一个空的远程git存储库(在下面的示例中,我将其称为 RemoteRepository ) li>


    推送至远程




    1. 打开Xcode中的 Organizer ,转到 Repositories 标签。

    2. 首先点击远程然后在添加远程




    3. 输入远程存储库的远程名称​​和位置 on create



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




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




    6. 现在您的旧项目已发布到GitHub上 img src =https://i.stack.imgur.com/kIQpN.pngalt =GitHub上的结果>


    我希望它也适用于你!在我的情况下,它适用于每个远程git存储库

    请与我联系 twitter 如果有什么不清楚的地方或者用英文写得不好!

    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?

    解决方案

    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"

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

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

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

    6. 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!

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

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