.gitignore 文件,我应该把它放在我的 xcode 项目中的什么位置?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9672319/
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
.gitignore file, where should I put it in my xcode project?
提问by Mauricio Alberto Barragn Huert
I want git to ignore my UserInterfaceState.xcuserstate
file in my XCode4 project, but where should I put the .gitignore
file?, is it inside the .git
folder? or out? The .git
is in same folder with the ProjectName.xcodeproj
file
我想让 git 忽略我的UserInterfaceState.xcuserstate
XCode4 项目中的文件,但是我应该把.gitignore
文件放在哪里?,它在.git
文件夹中吗?还是出去?该.git
是在同一文件夹与ProjectName.xcodeproj
文件
回答by Daniel Ribeiro
You can have a .gitignore
in every single directory of your project.
您可以.gitignore
在项目的每个目录中都有一个。
However, the best practice is to have one single .gitignore
file on the project root directory, and place all files that you want to ignore in it, like this:
但是,最好的做法是.gitignore
在项目根目录下只有一个文件,并将所有要忽略的文件放入其中,如下所示:
ignoredFile.whatever
ignoredDirectory/*
directory/ignoredFileInsideDirectory
.svn
Once you create the .gitignore
file, the ignore files that have changes or are new into the repository will not be shown to as waiting for commit.
创建.gitignore
文件后,已更改或新加入存储库的忽略文件将不会显示为等待提交。
You can also have one global local git ignore file, that will manage all of your git repositories.
您还可以拥有一个全局本地 git ignore 文件,该文件将管理您的所有 git 存储库。
git config --global core.excludesfile ~/.gitignore_global
git config --global core.excludesfile ~/.gitignore_global
This alternative is particularly interesting for ignored files that are non-project related, such as IDE related files and so on.
对于与项目无关的忽略文件,例如 IDE 相关文件等,此替代方法特别有趣。
回答by Khamidulla
There are there approaches to ignore files in git:
有一些方法可以忽略 git 中的文件:
- 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. - 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. - 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.
- 全局 git ignore:- 在这种方法中,您的自定义规则将应用于您机器中的每个 git 目录。通常这个文件可能在
~/.gitignore_global
路径下创建。如果您想排除由操作系统或任何其他日志记录、兑现等工具生成的某些类型文件,则此方法很好。 - Per-repository git ignore:- 在这种方法中,您的自定义规则将应用于您机器中的特定 git 目录。可以将每个存储库的本地规则添加到
.git/info/exclude
存储库中的文件中。该文件下指定的规则不会被提交,这意味着它不会与其他人共享。通常这种方法有助于防止提交本地生成的文件。例如,对于由您的编辑器创建的文件。 - 每个路径 git ignore:- 在这种情况下,您的自定义规则将应用于特定的 git 存储库子路径。您可以
.gitignore
在特定存储库的任何子路径中创建。这种方法通常用于忽略特定存储库的特定文件夹下的某些类型的文件。虽然此文件可以通过其他路径和其他存储库添加到版本控制中。
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.
因此,我对您的建议是,如果您想忽略UserInterfaceState.xcuserstate
所有存储库中的特定文件 ( ),最好的方法是使用全局 git ignore 方法。但是,如果您的文件仅在特定存储库中生成,您可以使用每个存储库的 git ignore 方法。
For more information you can read thisgreat 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.
有关更多信息,您可以阅读这篇很棒的博客文章。并且可以在此处找到每种语言特定的 git ignore 规则。您可以使用此网站为特定语言、工具或操作系统自动生成通用的 git ignore 规则。
回答by heinrich5991
You should put the .gitignore file into the project root directory.
您应该将 .gitignore 文件放入项目根目录。
回答by VonC
where should i put the
.gitignore
file?, is it inside the .git folder?
我应该把
.gitignore
文件放在哪里?,它在 .git 文件夹中吗?
There is no .gitignore
inside a .git
folder.
The is however a .git/info/exclude
file, which allows you to exclude a file locally, generally when you want to exclude a file only for this specific repo (with an alias like this one):
文件夹.gitignore
里面没有.git
。
然而.git/info/exclude
,这是一个文件,它允许您在本地排除文件,通常当您只想排除此特定存储库的文件时(具有像这样的别名):
git config alias.exclude "!sh -c 'echo \"\" >> .git/info/exclude' -"
git exclude UserInterfaceState.xcuserstate
If you need to exclude this file for allsimilar project, as Elnur Abdurrakhimovmentioned in his answer, exclude it globally.
如果您需要为所有类似项目排除此文件,如Elnur Abdurrakhimov在他的回答中提到的,请在全局范围内排除它。
echo UserInterfaceState.xcuserstate >> ~/.gitignore
But, as mentioned in "Do we need to check in *.xcuserstate?", if it is a typeof file which should be ignored by any user of that repo, I would actually version a .gitignore at the top of the repo, with a content similar to:
但是,正如“我们需要检查 *.xcuserstate 吗?”中提到的,如果它是一种应该被该 repo 的任何用户忽略的文件类型,我实际上会在 repo 的顶部版本一个 .gitignore,内容类似于:
*.xcuserstate
That way, any user of that repo won't even realize that this file exists and is generated (whatever its name is): it won't show up in a git status
ever.
这样,该 repo 的任何用户甚至都不会意识到这个文件的存在和生成(不管它的名字是什么):它永远不会出现git status
。
Or you can ignore xcuserdata/
entirely (either in a global .gitignore
, or in a versioned one, like the generic GitHub Objective-C.gitignore
file.
或者您可以完全忽略xcuserdata/
(在全局.gitignore
或版本控制中,如通用 GitHubObjective-C.gitignore
文件。
回答by Elnur Abdurrakhimov
You should notput tool-specific files into a project's .gitignore
file — unless that tool is required to be used by each developer of the project.
你应该不会把刀具专用文件到项目的.gitignore
文件-除非需要该工具由项目的每个开发人员使用。
Instead, create your personal global .gitignore
file in your home directory and activate it:
相反,.gitignore
在您的主目录中创建您的个人全局文件并激活它:
git config --global core.excludesfile ~/.gitignore
Now you can put whatever files are generated by your development tools into your .gitignore
file.
现在您可以将开发工具生成的任何文件放入您的.gitignore
文件中。
回答by Ajey
typically, its best practice to include the .gitignore
file in the project's root directory
通常,最佳做法是将.gitignore
文件包含在项目的根目录中