在 Xcode 中为预先存在的项目设置 git 存储库

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11021626/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 04:26:04  来源:igfitidea点击:

Setting up a git repository in Xcode for a pre-existing project

xcodegitversion-control

提问by Joey

Possible Duplicate:
Using Git with an existing Xcode project

可能的重复:
在现有的 Xcode 项目中使用 Git

Setting up a git repository in Xcode after a project was created. (i.e. you did not create a git repository when creating the project)

创建项目后在 Xcode 中设置 git 存储库。(即你在创建项目时没有创建git仓库)

采纳答案by Joey

  1. Quit Xcode (not sure if this is necessary but I do it just in case)
  2. Run Terminal
  3. Get into the project folder directory
  4. find .
  5. Find the file that says "UserInterfaceState.xcuserstate" and copy the entire filename up to the ./
  6. echo "paste the UserInterfaceState.xcuserstate file here" >.gitignore
  7. cat .gitignore
  8. git init
  9. git add .
  10. git commit -m "You can type a comment here like now under source control"
  1. 退出 Xcode(不确定是否有必要,但我这样做是为了以防万一)
  2. 运行终端
  3. 进入项目文件夹目录
  4. 找 。
  5. 找到显示“UserInterfaceState.xcuserstate”的文件并将整个文件名复制到 ./
  6. echo "在此处粘贴 UserInterfaceState.xcuserstate 文件" >.gitignore
  7. 猫.gitignore
  8. 混帐初始化
  9. git 添加。
  10. git commit -m "你可以像现在一样在源代码控制下在这里输入注释"

You now have a repository and your project is under source control

您现在有一个存储库并且您的项目处于源代码控制之下

回答by Motti Shneor

Last answer works OK, but is rather lengthy and incompatible with newer Xcode versions. I will try to reiterate it better:

最后一个答案工作正常,但相当冗长且与较新的 Xcode 版本不兼容。我将尝试更好地重申它:

  1. Choose your git repository folder (directory) usually this will be the directory containing the Xcode workspace or project.
  2. In that directory, create a text file named ".gitignore", and put the following contents into it:

    UserInterfaceState.xcuserstate
    build
    *.pbxuser
    *.perspectivev3
    *.mode1v3
    *~
    *~.nib
    *~.xib 
    .DS_Store 
    xcuserdata/
    
  3. Quit Xcode (If it was open)
  4. In Terminal do the following:

    \> cd <path of the repository folder>
    \> git init
    \> git add .
    \> git commit -m "Initial commit - or whatever text you'd prefer"
    
  1. 选择您的 git 存储库文件夹(目录)通常这将是包含 Xcode 工作区或项目的目录。
  2. 在该目录中,创建一个名为“.gitignore”的文本文件,并将以下内容放入其中:

    UserInterfaceState.xcuserstate
    build
    *.pbxuser
    *.perspectivev3
    *.mode1v3
    *~
    *~.nib
    *~.xib 
    .DS_Store 
    xcuserdata/
    
  3. 退出 Xcode(如果它是打开的)
  4. 在终端中执行以下操作:

    \> cd <path of the repository folder>
    \> git init
    \> git add .
    \> git commit -m "Initial commit - or whatever text you'd prefer"
    

You're done! Open the workspace/project in Xcode and examine your repository in the organizer window.

你完成了!在 Xcode 中打开工作区/项目并在管理器窗口中检查您的存储库。