简体   繁体   English

将Git添加到现有Xcode 9项目

[英]Add Git to Existing Xcode 9 Project

I ran into some issues when creating my Xcode project that really screwed up the Git repository. 在创建Xcode项目时确实遇到了一些问题,这些项目确实搞砸了Git存储库。 It had references to the build folder and a bunch of other files I didn't want in there. 它引用了build文件夹和其他我不想在其中的其他文件。 It's a fairly new project so discarding past commits is fine. 这是一个相当新的项目,因此可以丢弃过去的提交。 Therefore I removed the .git folder. 因此,我删除了.git文件夹。

I've since then gone back into Xcode and Source Control/Create Git Repositories. 从那以后,我回到了Xcode和源代码控制/创建Git存储库。 I create a repository for my project from there. 我从那里为我的项目创建一个存储库。

However none of my files are able to be committed as they obviously have not changed but I need to do an Initial Commit. 但是,我的文件都无法提交,因为它们显然没有更改,但是我需要执行“初始提交”。

I've seen many other posts about this where they state to use "git add ." 我看过许多关于此的其他文章,他们声明使用“ git add”。 However this would then result in a bunch of files from my project and Build/ folder being committed as well as my Pods folder which I do not want to do. 但是,这将导致我的项目和Build /文件夹以及我不想执行的Pods文件夹中的大量文件被提交。 Committing the project files into the repository I know is a big no no. 将项目文件提交到我知道的存储库中是很大的不。 However I'm uncertain which files or folders to ignore. 但是我不确定要忽略哪些文件或文件夹。

Is there a way to get Xcode to create the repository as it does when you first create the project? 有没有一种方法可以像初次创建项目时那样使Xcode创建存储库? Or does someone know which project files should be committed and which ones should NOT be committed so I can create some .gitignore files in the project package to clear all that up? 还是有人知道应该提交哪些项目文件,哪些不应该提交,以便我可以在项目包中创建一些.gitignore文件来清除所有内容?

1) First in order to make git ignore certain files you will need .gitignore file here is one for Swift or Objective-C add it to your repository folder. 1)首先,为了使git忽略某些文件,您将需要.gitignore文件,这里是用于SwiftObjective-C的文件,将其添加到您的存储库文件夹中。

2) then you need to remove all committed files use this command in terminal after changing directory to repository folder 2)然后将目录更改为存储库文件夹后,需要在终端中使用此命令删除所有已提交的文件

git rm -r --cached . 

3) then add all files by using this command in terminal 3)然后在终端中使用此命令添加所有文件

git add .

4) and add the initial commit 4)并添加初始提交

git commit -am "initial commit"

if you didn't initialize git after removing .git folder skip step 2 如果删除.git文件夹后未初始化git,请跳过步骤2

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

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