.gitignore文件,我应该把它放在我的xcode项目中?

Mau*_*ert 102 git xcode gitignore

我希望git忽略我的UserInterfaceState.xcuserstateXCode4项目中的文件,但是我应该把.gitignore文件放在哪里?,它是否在.git文件夹中?还是出去?该.git是在同一文件夹与ProjectName.xcodeproj文件

Dan*_*iro 124

您可以.gitignore在项目的每个目录中拥有一个.

但是,最佳做法是.gitignore在项目根目录中包含一个文件,并将要忽略的所有文件放在其中,如下所示:

ignoredFile.whatever
ignoredDirectory/*
directory/ignoredFileInsideDirectory
.svn
Run Code Online (Sandbox Code Playgroud)

创建.gitignore文件后,对存储库进行更改或更新的忽略文件将不会显示为等待提交.

您还可以拥有一个全局本地git ignore文件,它将管理您的所有git存储库.

git config --global core.excludesfile ~/.gitignore_global

对于与项目无关的忽略文件,例如IDE相关文件等,此替代方案尤其有用.


Kha*_*lla 21

There are there approaches to ignore files in git:

  1. Global git ignore: - In this approach your custom rules will be applied to every git directory in your machine. Usually this file might be created under ~/.gitignore_global path. This approach good if you want to exclude some type files which is generated by OS or any other logging, cashing and etc. tools.
  2. Per-repository git ignore: - In this approach your custom rules will be applied to specific git directory in your machine. Local per-repository rules can be added to the .git/info/exclude file in your repository. The rules specified under this file will not be committed, which means it will not be shared with others. Generally this approach useful to prevent committing of locally generated files. For example, for files created by your editor.
  3. Per path git ignore: - In this case your custom rules will be applied to specific git repositories sub path. You can create .gitignore in any sub path of your specific repository. This approach usually used to ignore some types of file only under specific folder of specific repository. While this files can be added to version controlling by other paths and other repositories.

So, My suggest to you is, if you want to ignore your specific file (UserInterfaceState.xcuserstate) in your all repositories the best approach is to use global git ignore approach. However if your file is generated only in specific repository you can use per-repository git ignore approach.

For more information you can read this great blog post. And there per language specific git ignore rules can be founded here. And you can auto generate general git ignore rules for specific language, tool or os using this web site.


hei*_*991 20

您应该将.gitignore文件放入项目根目录中.


Von*_*onC 12

我应该把.gitignore文件放在哪里?,它在.git文件夹中吗?

文件夹.gitignore里面没有.git.
但是.git/info/exclude,它是一个文件,允许您在本地排除文件,通常当您只想为此特定仓库排除文件时(使用类似这样别名):

git config alias.exclude "!sh -c 'echo \"$1\" >> .git/info/exclude' -"
git exclude UserInterfaceState.xcuserstate
Run Code Online (Sandbox Code Playgroud)

如果您需要为所有类似的项目排除此文件,如答案中提到的Elnur Abdurrakhimov,则将其全局排除.

echo UserInterfaceState.xcuserstate >> ~/.gitignore
Run Code Online (Sandbox Code Playgroud)

但是,正如" 我们需要检入*.xcuserstate吗? "中提到的那样,如果它是一种应该被该repo的任何用户忽略的文件类型,我实际上会在repo的顶部版本化一个.gitignore,内容类似于:

*.xcuserstate 
Run Code Online (Sandbox Code Playgroud)

这样,该repo的任何用户都不会意识到该文件存在并生成(无论其名称是什么):它永远不会出现git status.

或者你可以完全忽略xcuserdata/(无论是全局的.gitignore,还是版本的,如通用的GitHubObjective-C.gitignore文件.


Eln*_*mov 9

你应该把特定工具的文件到项目的.gitignore文件-除非需要该工具由项目的每个开发人员使用.

而是.gitignore在您的主目录中创建您的个人全局文件并将其激活:

git config --global core.excludesfile ~/.gitignore
Run Code Online (Sandbox Code Playgroud)

现在,您可以将开发工具生成的任何文件放入.gitignore文件中.


Aje*_*jey 6

通常,最佳做法是将.gitignore文件包含在项目的根目录中