git .gitignore 文件属于哪里?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5698148/
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
Where does the .gitignore file belong?
提问by mishaF
Does the .gitignore file belong in the .git folder structure somewhere or in the main source files?
.gitignore 文件是否属于 .git 文件夹结构中的某个地方或主源文件?
回答by jmulho
Put .gitignore in the workingdirectory. It doesn't work if you put it in the .git (repository) directory.
将 .gitignore 放在工作目录中。如果你把它放在 .git (repository) 目录中,它就不起作用。
$ ls -1d .git*
.git
.gitignore
回答by Alan Haggai Alavi
As the other answers stated, you can place .gitignore
within any directory in a Git repository. However, if you need to have a private version of .gitignore
, you can add the rules to .git/info/exclude
file.
正如其他答案所述,您可以将其放置.gitignore
在 Git 存储库中的任何目录中。但是,如果您需要私有版本的.gitignore
,则可以将规则添加到.git/info/exclude
文件中。
回答by philipk
You can place .gitignore in any directory in git.
您可以将 .gitignore 放在 git 中的任何目录中。
It's commonly used as a placeholder file in folders, since folders aren't usually tracked by git.
它通常用作文件夹中的占位符文件,因为 git 通常不跟踪文件夹。
回答by Hraban Luyat
When in doubt just place it in the root of your repository. See https://help.github.com/articles/ignoring-files/for more information.
如有疑问,只需将其放在存储库的根目录中。有关更多信息,请参阅https://help.github.com/articles/ignoring-files/。
回答by Liran Brimer
If you want to do it globally, you can use the default path git will search for. Just place it inside a file named "ignore" in the path ~/.config/git
如果要全局执行,可以使用 git 将搜索的默认路径。只需将它放在路径中名为“ignore”的文件中~/.config/git
(so full path for your file is: ~/.config/git/ignore
)
(您的文件,以便完整路径是:~/.config/git/ignore
)
回答by XLE_22
You may also find a global .gitignore directly at the ~ path if you haven't created it in your folder project. This file is taken into account by all your .git projects.
如果您尚未在文件夹项目中创建它,您也可以直接在 ~ 路径中找到全局 .gitignore。您的所有 .git 项目都会考虑此文件。
回答by Thielicious
Also, if you create a new account on Github you will have the option to add .gitignore and it will be setup automatically on the right/standard location of your working place. You don't have to add anything in there at the begin, just alter the contents any time you want.
此外,如果您在 Github 上创建一个新帐户,您将可以选择添加 .gitignore,它会自动设置在您工作地点的正确/标准位置。您不必在开始时添加任何内容,只需随时更改内容即可。