简体   繁体   English

使用Xcode将现有项目添加到BitBucket

[英]Add existing project to BitBucket using Xcode

I keep getting an error when I try to commit my project files using Xcode. 当我尝试使用Xcode提交项目文件时,我总是收到错误消息。

File -> Source Control -> Commit 文件->源代码管理->提交

"The operation could not be performed because no valid working copies were found." “由于找不到有效的工作副本,因此无法执行该操作。” "Please verify that your files are under source control and try again." “请验证您的文件在源代码控制下,然后重试。”

This is an existing project that is NOT under source control. 这是一个不受源代码控制的现有项目。 How do I get my project files under source control, using Xcode? 如何使用Xcode在源代码控制下获得项目文件?

EDIT: Answered my own question. 编辑:回答了我自己的问题。

Step 1) Restart Xcode 步骤1)重新启动Xcode

Step 2) Choose connect to repo 步骤2)选择连接到仓库

Step 3) Enter repo address 步骤3)输入回购地址

Step 4) Choose existing project folder you wish to place under version control 步骤4)选择要放置在版本控制下的现有项目文件夹

Step 5) Voila! 步骤5)瞧! :) :)

Since a lot of folks land here when they google "Add existing project to BitBucket using Xcode" and then click through to the link that goes to my blog post on the subject, I thought I would put the information here (in the spirit of SO which discourages link only answers.) 由于许多人在Google上搜索“使用Xcode将现有项目添加到BitBucket中”然后点击进入指向该主题的博客文章的链接时就落在此处,因此我认为我应该将信息放在此处(本着SO的精神不鼓励链接的唯一答案。)

NOTE: These instructions assume you have already made a local git repository for the project. 注意:这些说明假定您已经为项目创建了本地git存储库。 You may have done this at project creation. 您可能在项目创建时就已经这样做了。 If not, you will need to create the local git now. 如果没有,则需要立即创建本地git。 See this StackOverflow post for how to do that: https://stackoverflow.com/questions/19495141/add-local-repo-for-existing-xcode-5-project 请参阅此StackOverflow帖子以了解如何执行此操作: https : //stackoverflow.com/questions/19495141/add-local-repo-for-existing-xcode-5-project

For Xcode 9 and the new Beta UI for Bitbucket: 对于Xcode 9和Bitbucket的新Beta用户界面:

  1. Log into your BitBucket Account on their web site. 在其网站上登录您的BitBucket帐户。
  2. Click the Create button (plus sign + in the newest version of the web UI). 单击创建按钮(最新版本的Web UI中的加号+)。 And click Repository. 然后单击存储库。
  3. Give your new repository a name. 为您的新存储库命名。 Additional features for the repo can be configured under the Advanced menu. 存储库的其他功能可以在“高级”菜单下配置。 Make sure the check mark for Private is on if you desire that. 如果需要,请确保已选中“私人”的复选标记。 Verify that the repository type is Git. 验证存储库类型为Git。 If desired, add issue tracking, and a Wiki. 如果需要,添加问题跟踪和Wiki。 Select Objective C or Swift from the language drop down. 从语言下拉列表中选择“ Objective C”或“ Swift”。 Then Create Repository. 然后创建存储库。
  4. Next, you will want to add your code. 接下来,您将要添加代码。 On the top of the Overview page is a field with the HTTPS URL of your project. “概述”页面顶部是一个包含项目的HTTPS URL的字段。 It will look something like this: https://johndoe@bitbucket.org/xyzteam/xyzapp.git . 它看起来像这样: https://johndoe@bitbucket.org/xyzteam/xyzapp.git Highlight and copy that URL text. 突出显示并复制该URL文本。
  5. Run Xcode and load your project. 运行Xcode并加载您的项目。
  6. From the left pane in Xcode, select the Source Control Navigator. 在Xcode的左窗格中,选择Source Control Navigator。 Expand the project node. 展开项目节点。 Right click the Remotes node under your project. 右键单击项目下的“ Remotes”节点。 Select “Add Existing Remote…” 选择“添加现有的遥控器...”
  7. Give it a remote name, such as Bitbucket. 给它起一个远程名称,例如Bitbucket。 Paste the URL from step 4 into the Location. 将第4步中的URL粘贴到“位置”中。 Click Add. 单击添加。 It should now appear as a Remote location in the Source Control navigator. 现在,它应该在“源代码管理”导航器中显示为“远程”位置。
  8. Once your remote has been added, you should now be able to push to the remote. 添加遥控器后,现在应该可以将其推送到遥控器了。 Select Source Control/Push… It should show your Bitbucket remote as the destination and will show (Create) as this is the first push. 选择Source Control / Push…(源代码控制/推送...)。它将显示您的Bitbucket远程作为目标,并显示(创建),因为这是第一次推送。 Click Push. 单击推送。
  9. If this is the first time you are pushing this project to BitBucket, you will be asked for login credentials. 如果这是您第一次将此项目推送到BitBucket,则会要求您提供登录凭据。 The User Name will be prefilled from the URL, so enter the password. 用户名将从URL中预填,因此输入密码。 Click Okay and after some seconds, it should complete. 单击确定,几秒钟后,它应该完成。

If all goes well, you now have the repositories linked up. 如果一切顺利,那么您现在已经链接了存储库。 Go to the BitBucket site, select your repo and you should see the code. 转到BitBucket站点,选择您的仓库,您应该会看到代码。

For Xcode older than version 9 and the old Bitbucket UI: 对于版本9之前的Xcode和旧的Bitbucket UI:

  1. Log into your BitBucket Account on their web site. 在其网站上登录您的BitBucket帐户。

  2. Click the Create button. 单击创建按钮。

  3. Give your new repository a name, a description, and make sure the check mark for Private is on if you desire that. 给您的新存储库一个名称,一个描述,并确保在需要时选中“专用”复选标记。 Verify that the repository type is Git. 验证存储库类型为Git。 If desired, add issue tracking, and a Wiki. 如果需要,添加问题跟踪和Wiki。 Select Objective C or Swift from the language drop down. 从语言下拉列表中选择“ Objective C”或“ Swift”。 Then Create it. 然后创建它。

  4. Next, you will want to add your code. 接下来,您将要添加代码。 I am assuming you have an existing project. 我假设您已有一个项目。 On the page, you will select “I have an existing project” link from the Command line section. 在页面上,您将从命令行部分中选择“我有一个现有项目”链接。

  5. You will see instructions for linking your local git repository to the remote. 您将看到有关将本地git存储库链接到远程服务器的说明。 There is no need to follow those instructions. 无需遵循这些说明。 However, you will see an https url listed. 但是,您将看到列出的https网址。 It will look something like this: https://johndoe@bitbucket.org/xyzteam/xyzapp.git . 它看起来像这样: https://johndoe@bitbucket.org/xyzteam/xyzapp.git Highlight and copy that URL text. 突出显示并复制该URL文本。

  6. Run Xcode and load your project. 运行Xcode并加载您的项目。

  7. From the main menu, select Source Control. 从主菜单中,选择“源代码管理”。 Under the gray “Working Copy” item, you will see a menu with your local git repo name and the currently active branch. 在灰色的“工作副本”项下,您将看到一个菜单,其中包含您的本地git repo名称和当前活动的分支。 Expand this menu and you will see an option to Configure [Your project]…. 展开此菜单,您将看到配置[您的项目]…的选项。 Select this. 选择这个。

  8. Select the Remotes pane from this screen. 从此屏幕选择“远程控制”窗格。 At the bottom, click the plus +. 在底部,单击加号+。 Select Add Remote… 选择添加远程…

  9. Now you need a name and a URL. 现在,您需要一个名称和一个URL。 For the name, typically just use your project name, then paste the URL copied earlier in step 5. Some people have found that they must remove the user name portion of the URL. 对于名称,通常只使用您的项目名称,然后粘贴先前在步骤5中复制的URL。有些人发现他们必须删除URL的用户名部分。 Per the example, remove “johndoe@”. 在此示例中,删除“ johndoe @”。 This may have to do with whether your project is set up as a team project, or an individual project. 这可能与您的项目是设置为团队项目还是单个项目有关。

  10. Click Add Remote. 单击添加远程。 Click Done. 单击完成。

  11. Once your remote has been added, you should now be able to push to the remote. 添加遥控器后,现在应该可以将其推送到遥控器了。 Select Source Control/Push…. 选择源代码控制/推送…。 If this is the first time you are pushing this project to BitBucket, you may be asked about keychain access and/or login credentials. 如果这是您第一次将此项目推送到BitBucket,则可能会询问您有关钥匙串访问和/或登录凭据的信息。 Enter the appropriate responses, such as Allow for keychain. 输入适当的响应,例如“允许钥匙串”。 If you have already done this before, it will simply use the keychain data without further prompting. 如果您之前已经完成过此操作,它将仅使用钥匙串数据而无需进一步提示。

If all goes well, you now have the repositories linked up. 如果一切顺利,那么您现在已经链接了存储库。 Go to the BitBucket site, select your repo and you should see the code. 转到BitBucket站点,选择您的仓库,您应该会看到代码。

If you want to see a version of this information with screen shots, see my blog post . 如果您想通过屏幕截图查看此信息的版本,请参阅我的博客文章

Login your bit bucket account and Create a repository in your account 登录您的位bucket account并在您的帐户中创建repository

open terminal run these following command 打开terminal运行以下command

1- cd /path/to/your/repo 1- cd /path/to/your/repo

2- git remote add origin <url of your repository > 2- git remote add origin <url of your repository >

3- git push -f origin master 3- git push -f origin master

it works for me, Thanks. 对我有用,谢谢。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM