在现有 Xcode 项目中使用 Git
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5383609/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Using Git with an existing Xcode project
提问by AndyD273
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 配置和最佳实践的任何好的演练,那就太好了。我玩游戏有点晚了,所以任何能让我加快速度的东西都会很酷。
回答by MCannon
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 中管理它。
回答by Suragch
Xcode 7 (and 8)
Xcode 7(和 8)
If you were starting a new project you would just check Create Git repositoryduring the setup. (Then skip down to the Commit part below.)
如果您正在开始一个新项目,您只需在设置期间检查创建 Git 存储库。(然后跳到下面的提交部分。)
But it you are working with an existing project, go to Xcode> Preferences...> Source Controland check the Enable Source Controlbox.
但如果您正在处理现有项目,请转到Xcode> Preferences...> Source Control并选中Enable Source Control框。
Then in the main Source Controlmenu choose Create Working Copy....
然后在主Source Control菜单中选择Create Working Copy...。
(If you get a "Please tell me who you are" error the see this question/answeror 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 Controlmenu and choose Commit.
完成后,对您的 Xcode 项目文件之一进行任何更改。然后返回到Source Control菜单并选择Commit。
And write a commit message and click the Commitbutton. (If the commit button is disabled, then make any minor change to your project and try again.)
并编写提交消息并单击“提交”按钮。(如果提交按钮被禁用,则对您的项目进行任何小的更改并重试。)
In Github sign in and create a new repository.
在 Github 中登录并创建一个新的存储库。
Call it whatever you want, but don'tadd a README or .gitignore or license yet. You can add those things later. Doing so now will make the syncing more difficult.
随意命名,但不要添加 README 或 .gitignore 或许可证。您可以稍后添加这些内容。现在这样做会使同步更加困难。
Copy the link to your repository.
将链接复制到您的存储库。
Go to Source Control> your branch name> Configure.
转到Source Control>您的分支名称> Configure。
Click the Remotestab > "+" button > Add remote....
点击遥控器选项卡>“ +”按钮>添加远程...。
Enter the github repository name and paste in the address.
输入github仓库名称并粘贴地址。
After adding the remote, click Pushin the Source Controlmenu. Enter your github user name and password. That's it. You project should be copied to github now.
添加遥控器后,单击Source Control菜单中的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 Pushagain.)
(一开始我在接受我的用户名和密码时遇到了一些麻烦。如果发生这种情况,你去Xcode> Preferences...> Accounts> your new repository。在那里输入你的用户名和密码,然后再次尝试Push。)
You can add a README and other files, but if you do it from the web, you will have to do Source Control> Pullin Xcode before you con commit other changes.
您可以添加 README 和其他文件,但如果您是从 Web 上添加的,则必须先执行Source Control> Pullin Xcode,然后再提交其他更改。
Now any time you make changes in Xcode, all you have to do is Commitand Push.
现在,无论何时您在 Xcode 中进行更改,您所要做的就是Commit和Push。
I learned this method mostly from here.
我主要从这里学到了这种方法。
See also
也可以看看
回答by nuclearnova
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
我刚刚经历了为几个项目执行此操作的过程,并遇到了一些问题。这是我的过程,主要是从这个页面/网站上的其他答案拼凑起来的。顺序在这里很重要
- Open terminal and cd into the directory containing the .xcodeproj file
- git init
- 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/
- Not sure if this is needed, but I used terminal to cp info/exclude over to a .gitignore file
- git add .
- git commit -m "Initial commit"
- 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
- In the repositories tab of the organizer I then branch off the master branch/switch into whatever version I'm working on.
- 打开终端并 cd 进入包含 .xcodeproj 文件的目录
- 混帐初始化
- 在 finder 中输入新创建的 .git 文件夹(与 .xcodeproj 文件在同一目录中)。查找信息/排除,打开并添加这些行,.DS_Store 和 xcuserdata/
- 不确定是否需要这样做,但我使用终端将信息/排除转换为 .gitignore 文件
- git 添加。
- git commit -m "初始提交"
- 现在让 XCode 实际查看 repo。在项目管理器中,您首先必须从项目选项卡中删除项目。然后只需重新打开项目即可将其恢复。这将检测刚刚创建的 GIT 存储库
- 在组织者的存储库选项卡中,我将主分支/切换到我正在处理的任何版本。
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 新手来说绝对是一个挑战
回答by Joey
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 中执行任何操作时都会更新此文件,即使它非常简单并且在您的项目中浏览文件或文件夹。
回答by Ram G.
if your XCODE 7 is not connecting with existing GIT repository. Try following
如果您的 XCODE 7 未与现有的 GIT 存储库连接。尝试以下
xcrun git config --global user.email [email protected]
xcrun git config --global user.name "your name"
回答by Vikram Sinha
Note:Specially for Xcode 11
Note:Specially for Xcode 11
CD to project directory using terminal
使用终端 CD 到项目目录
git init
混帐初始化
git add .
git 添加。
git commit -m "Initial commit"
git commit -m "初始提交"
After this restart the Xcode and choose Source Control Navigator and then select the master and right click then choose option "Create Remote"
重新启动Xcode并选择Source Control Navigator,然后选择master并右键单击然后选择选项“Create Remote”