本文翻译自:Where does the .gitignore file belong?
.gitignore文件是属于某个地方还是主源文件中的.git文件夹结构?
#1楼
参考:https://stackoom.com/question/NuLc/gitignore文件属于哪里
#2楼
Put .gitignore in the working directory. 将.gitignore放在工作目录中。 It doesn't work if you put it in the .git (repository) directory. 如果将它放在.git(存储库)目录中,它将不起作用。
$ ls -1d .git*
.git
.gitignore
#3楼
If you want to do it globally, you can use the default path git will search for. 如果你想全局地做,你可以使用git将搜索的默认路径。 Just place it inside a file named "ignore" in the path ~/.config/git
只需将它放在路径~/.config/git
名为“ignore”的文件中即可
(so full path for your file is: ~/.config/git/ignore
) (所以你的文件的完整路径是: ~/.config/git/ignore
)
#4楼
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. 此外,如果您在Github上创建一个新帐户,您可以选择添加.gitignore,它将自动设置在您工作地点的右侧/标准位置。 You don't have to add anything in there at the begin, just alter the contents any time you want. 您不必在开始时添加任何内容,只需随时更改内容即可。
#5楼
You may also find a global .gitignore directly at the ~ path if you haven't created it in your folder project. 如果您尚未在文件夹项目中创建全局.gitignore,也可以直接在〜路径中找到它。 This file is taken into account by all your .git projects. 所有.git项目都会考虑此文件。
#6楼
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通常不会跟踪文件夹。