简体   繁体   中英

Add Git to Existing Xcode 9 Project

I ran into some issues when creating my Xcode project that really screwed up the Git repository. It had references to the build folder and a bunch of other files I didn't want in there. It's a fairly new project so discarding past commits is fine. Therefore I removed the .git folder.

I've since then gone back into Xcode and Source Control/Create Git Repositories. 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 ." 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. 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? 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?

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.

2) then you need to remove all committed files use this command in terminal after changing directory to repository folder

git rm -r --cached . 

3) then add all files by using this command in terminal

git add .

4) and add the initial commit

git commit -am "initial commit"

if you didn't initialize git after removing .git folder skip step 2

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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