使用Git与现有的XCode项目。

时间:2023-01-24 07:29:51

I am trying to figure out how to use git in my project workflow, and I have an existing XCode project that I want to put into the repository. I think I have the repository set up correctly under organizer, but the Source Control menu is grayed out.
Apparently, it's easy to do if you start a new project, but how do I import an existing project with snapshots and everything?

我正在试图弄清楚如何在我的项目工作流程中使用git,并且我有一个现有的XCode项目,我想把它放到存储库中。我想我已经把存储库设置正确了,但是源控制菜单是灰色的。显然,如果您启动了一个新项目,那么很容易做到,但是如何导入一个现有项目的快照和所有内容呢?

I'm using XCode 4 and git 1.7.4

我使用XCode 4和git 1.7.4。

Also, if there are any good walkthroughs on git configuration and best practices, that would be nice. I'm a little late to the game, so anything that can get me up to speed would be cool.

另外,如果有任何关于git配置和最佳实践的好的演练,那将是不错的。我有点晚了,所以任何能让我加快速度的东西都是很酷的。

5 个解决方案

#1


163  

GitHub has some very good git tutorials at help.github.com.

GitHub在help.github.com上有一些很好的git教程。

to do the initial setup of a repository, open up a terminal window, and CD to the project directory. once there, type

要完成存储库的初始设置,请打开终端窗口,并将CD打开到项目目录。一旦有,类型

git init
git add .
git commit -m "Initial commit"

Restart Xcode. The repository should now be set up, and you will be able to manage it in xcode 4.

重启Xcode。现在应该设置存储库,您将能够在xcode 4中管理它。

#2


93  

Xcode 7 (and 8)

If you were starting a new project you would just check Create Git repository during the setup. (Then skip down to the Commit part below.)

如果您正在启动一个新项目,您将在安装过程中检查创建Git仓库。(然后跳到下面的提交部分。)

使用Git与现有的XCode项目。

But it you are working with an existing project, go to Xcode > Preferences... > Source Control and check the Enable Source Control box.

但是您正在使用一个现有的项目,转到Xcode >首选项…b0源代码控制和检查启用源代码控制框。

使用Git与现有的XCode项目。

Then in the main Source Control menu choose Create Working Copy....

然后在主源控制菜单中选择创建工作副本

使用Git与现有的XCode项目。

(If you get a "Please tell me who you are" error the see this question/answer or one of the other linked questions there.)

(如果你得到一个“请告诉我你是谁”的错误,你就会看到这个问题/答案或者其他相关的问题。)

When that has finished, make any change to one of your Xcode project files. Then go back to the Source Control menu and choose Commit.

完成后,对您的Xcode项目文件进行任何更改。然后返回源控制菜单并选择Commit。

使用Git与现有的XCode项目。

And write a commit message and click the Commit button. (If the commit button is disabled, then make any minor change to your project and try again.)

并写入提交消息并单击commit按钮。(如果提交按钮被禁用,那么对您的项目进行任何微小的更改,然后重试。)

使用Git与现有的XCode项目。

In Github sign in and create a new repository.

在Github中登录并创建一个新的存储库。

使用Git与现有的XCode项目。

Call it whatever you want, but don't add a README or .gitignore or license yet. You can add those things later. Doing so now will make the syncing more difficult.

无论你想要什么,都可以叫它,但不要添加一个README或.gitignore或许可。稍后您可以添加这些东西。这样做将使同步变得更加困难。

使用Git与现有的XCode项目。

Copy the link to your repository.

复制到存储库的链接。

使用Git与现有的XCode项目。

Go to Source Control > your branch name > Configure.

到源代码控制>您的分支名称>配置。

使用Git与现有的XCode项目。

Click the Remotes tab > "+" button > Add remote....

点击Remotes标签>“+”按钮>添加远程

使用Git与现有的XCode项目。

Enter the github repository name and paste in the address.

输入github存储库名称并在地址中粘贴。

使用Git与现有的XCode项目。

After adding the remote, click Push in the Source Control menu. Enter your github user name and password. That's it. You project should be copied to github now.

添加远程后,单击源代码控制菜单中的Push。输入您的github用户名和密码。就是这样。你的项目现在应该被复制到github上。

(I had some trouble getting my username and password accepted at first. If that happens to you go to Xcode > Preferences... > Accounts > your new repository. Enter your user name and password there and then try the Push again.)

我的用户名和密码一开始就被接受了。如果你遇到Xcode >偏好…>帐户>您的新存储库。输入您的用户名和密码,然后再试一次。

使用Git与现有的XCode项目。

You can add a README and other files, but if you do it from the web, you will have to do Source Control > Pull in Xcode before you con commit other changes.

您可以添加一个README和其他文件,但是如果您从web上执行,您将不得不在您进行其他更改之前在Xcode中执行源代码控制>。

Now any time you make changes in Xcode, all you have to do is Commit and Push.

现在,任何时候在Xcode中进行更改时,所要做的就是提交和推动。

I learned this method mostly from here.

我从这里学到了这个方法。

See also

#3


44  

I just went through the process of doing this for several projects, and ran into some issues. Here was my process, mostly pieced together from the other answers on this page/site. Order is very important here

我刚刚经历了几个项目的过程,遇到了一些问题。这是我的过程,大部分是由这个页面上的其他答案拼凑起来的。这里的秩序很重要。

  1. Open terminal and cd into the directory containing the .xcodeproj file
  2. 打开终端和cd到包含.xcodeproj文件的目录中。
  3. git init
  4. git init
  5. In finder enter the newly created .git folder (in the same directory as the .xcodeproj file). Find info/exclude, open and add these lines, .DS_Store and xcuserdata/
  6. 在finder中输入新创建的.git文件夹(在与.xcodeproj文件相同的目录中)。查找信息/排除,打开并添加这些行,.DS_Store和xcuserdata/。
  7. Not sure if this is needed, but I used terminal to cp info/exclude over to a .gitignore file
  8. 不确定是否需要,但我使用了终端到cp info/排除到.gitignore文件。
  9. git add .
  10. git添加。
  11. git commit -m "Initial commit"
  12. git提交-m“初始提交”
  13. Now to get XCode to actually see the repo. In the project organizer, you first have to delete the project from the Projects tab. Then simply re-open the project to get it back. This will detect the GIT repository just created
  14. 现在要让XCode真正看到repo。在项目管理器中,您首先必须从Projects选项卡中删除项目。然后简单地重新打开项目,让它返回。这将检测刚刚创建的GIT存储库。
  15. In the repositories tab of the organizer I then branch off the master branch/switch into whatever version I'm working on.
  16. 在组织者的储存库选项卡中,我将主分支/切换到我正在处理的任何版本。

Hopefully this helps someone without being too redundant. What now seems simple was definitely a challenge for someone new to GIT with existing projects

希望这能帮助别人,而不是太多余。现在看来很简单,对于一个新到GIT和现有项目的人来说无疑是一个挑战!

#4


9  

Check out my post on this topic Setting up a git repository in XCode for a pre-existing project. The above is correct, but it will include UserInterfaceState in your changes as you commit and this could be annoying because this file updates everytime you do anything in xcode, even if it is as simple and navigating through files or folders in your project.

查看我关于这个主题的文章,在XCode中为已有的项目设置一个git仓库。上面的内容是正确的,但是它将在您提交的更改中包含UserInterfaceState,这可能很烦人,因为每当您在xcode中做任何事情时,这个文件都会更新,即使它很简单,并且在您的项目中通过文件或文件夹导航。

#5


1  

if your XCODE 7 is not connecting with existing GIT repository. Try following

如果XCODE 7没有与现有的GIT存储库连接。尝试后

xcrun git config --global user.email your@email.com
xcrun git config --global user.name "your name"

#1


163  

GitHub has some very good git tutorials at help.github.com.

GitHub在help.github.com上有一些很好的git教程。

to do the initial setup of a repository, open up a terminal window, and CD to the project directory. once there, type

要完成存储库的初始设置,请打开终端窗口,并将CD打开到项目目录。一旦有,类型

git init
git add .
git commit -m "Initial commit"

Restart Xcode. The repository should now be set up, and you will be able to manage it in xcode 4.

重启Xcode。现在应该设置存储库,您将能够在xcode 4中管理它。

#2


93  

Xcode 7 (and 8)

If you were starting a new project you would just check Create Git repository during the setup. (Then skip down to the Commit part below.)

如果您正在启动一个新项目,您将在安装过程中检查创建Git仓库。(然后跳到下面的提交部分。)

使用Git与现有的XCode项目。

But it you are working with an existing project, go to Xcode > Preferences... > Source Control and check the Enable Source Control box.

但是您正在使用一个现有的项目,转到Xcode >首选项…b0源代码控制和检查启用源代码控制框。

使用Git与现有的XCode项目。

Then in the main Source Control menu choose Create Working Copy....

然后在主源控制菜单中选择创建工作副本

使用Git与现有的XCode项目。

(If you get a "Please tell me who you are" error the see this question/answer or one of the other linked questions there.)

(如果你得到一个“请告诉我你是谁”的错误,你就会看到这个问题/答案或者其他相关的问题。)

When that has finished, make any change to one of your Xcode project files. Then go back to the Source Control menu and choose Commit.

完成后,对您的Xcode项目文件进行任何更改。然后返回源控制菜单并选择Commit。

使用Git与现有的XCode项目。

And write a commit message and click the Commit button. (If the commit button is disabled, then make any minor change to your project and try again.)

并写入提交消息并单击commit按钮。(如果提交按钮被禁用,那么对您的项目进行任何微小的更改,然后重试。)

使用Git与现有的XCode项目。

In Github sign in and create a new repository.

在Github中登录并创建一个新的存储库。

使用Git与现有的XCode项目。

Call it whatever you want, but don't add a README or .gitignore or license yet. You can add those things later. Doing so now will make the syncing more difficult.

无论你想要什么,都可以叫它,但不要添加一个README或.gitignore或许可。稍后您可以添加这些东西。这样做将使同步变得更加困难。

使用Git与现有的XCode项目。

Copy the link to your repository.

复制到存储库的链接。

使用Git与现有的XCode项目。

Go to Source Control > your branch name > Configure.

到源代码控制>您的分支名称>配置。

使用Git与现有的XCode项目。

Click the Remotes tab > "+" button > Add remote....

点击Remotes标签>“+”按钮>添加远程

使用Git与现有的XCode项目。

Enter the github repository name and paste in the address.

输入github存储库名称并在地址中粘贴。

使用Git与现有的XCode项目。

After adding the remote, click Push in the Source Control menu. Enter your github user name and password. That's it. You project should be copied to github now.

添加远程后,单击源代码控制菜单中的Push。输入您的github用户名和密码。就是这样。你的项目现在应该被复制到github上。

(I had some trouble getting my username and password accepted at first. If that happens to you go to Xcode > Preferences... > Accounts > your new repository. Enter your user name and password there and then try the Push again.)

我的用户名和密码一开始就被接受了。如果你遇到Xcode >偏好…>帐户>您的新存储库。输入您的用户名和密码,然后再试一次。

使用Git与现有的XCode项目。

You can add a README and other files, but if you do it from the web, you will have to do Source Control > Pull in Xcode before you con commit other changes.

您可以添加一个README和其他文件,但是如果您从web上执行,您将不得不在您进行其他更改之前在Xcode中执行源代码控制>。

Now any time you make changes in Xcode, all you have to do is Commit and Push.

现在,任何时候在Xcode中进行更改时,所要做的就是提交和推动。

I learned this method mostly from here.

我从这里学到了这个方法。

See also

#3


44  

I just went through the process of doing this for several projects, and ran into some issues. Here was my process, mostly pieced together from the other answers on this page/site. Order is very important here

我刚刚经历了几个项目的过程,遇到了一些问题。这是我的过程,大部分是由这个页面上的其他答案拼凑起来的。这里的秩序很重要。

  1. Open terminal and cd into the directory containing the .xcodeproj file
  2. 打开终端和cd到包含.xcodeproj文件的目录中。
  3. git init
  4. git init
  5. In finder enter the newly created .git folder (in the same directory as the .xcodeproj file). Find info/exclude, open and add these lines, .DS_Store and xcuserdata/
  6. 在finder中输入新创建的.git文件夹(在与.xcodeproj文件相同的目录中)。查找信息/排除,打开并添加这些行,.DS_Store和xcuserdata/。
  7. Not sure if this is needed, but I used terminal to cp info/exclude over to a .gitignore file
  8. 不确定是否需要,但我使用了终端到cp info/排除到.gitignore文件。
  9. git add .
  10. git添加。
  11. git commit -m "Initial commit"
  12. git提交-m“初始提交”
  13. Now to get XCode to actually see the repo. In the project organizer, you first have to delete the project from the Projects tab. Then simply re-open the project to get it back. This will detect the GIT repository just created
  14. 现在要让XCode真正看到repo。在项目管理器中,您首先必须从Projects选项卡中删除项目。然后简单地重新打开项目,让它返回。这将检测刚刚创建的GIT存储库。
  15. In the repositories tab of the organizer I then branch off the master branch/switch into whatever version I'm working on.
  16. 在组织者的储存库选项卡中,我将主分支/切换到我正在处理的任何版本。

Hopefully this helps someone without being too redundant. What now seems simple was definitely a challenge for someone new to GIT with existing projects

希望这能帮助别人,而不是太多余。现在看来很简单,对于一个新到GIT和现有项目的人来说无疑是一个挑战!

#4


9  

Check out my post on this topic Setting up a git repository in XCode for a pre-existing project. The above is correct, but it will include UserInterfaceState in your changes as you commit and this could be annoying because this file updates everytime you do anything in xcode, even if it is as simple and navigating through files or folders in your project.

查看我关于这个主题的文章,在XCode中为已有的项目设置一个git仓库。上面的内容是正确的,但是它将在您提交的更改中包含UserInterfaceState,这可能很烦人,因为每当您在xcode中做任何事情时,这个文件都会更新,即使它很简单,并且在您的项目中通过文件或文件夹导航。

#5


1  

if your XCODE 7 is not connecting with existing GIT repository. Try following

如果XCODE 7没有与现有的GIT存储库连接。尝试后

xcrun git config --global user.email your@email.com
xcrun git config --global user.name "your name"