Where does the .gitignore file belong?

◇◆丶佛笑我妖孽 提交于 2019-11-27 19:41:17

问题


Does the .gitignore file belong in the .git folder structure somewhere or in the main source files?


回答1:


Put .gitignore in the working directory. It doesn't work if you put it in the .git (repository) directory.

$ ls -1d .git*
.git
.gitignore



回答2:


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.




回答3:


You can place .gitignore in any directory in git.

It's commonly used as a placeholder file in folders, since folders aren't usually tracked by git.




回答4:


When in doubt just place it in the root of your repository. See https://help.github.com/articles/ignoring-files/ for more information.




回答5:


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

(so full path for your file is: ~/.config/git/ignore)




回答6:


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.




回答7:


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.



来源:https://stackoverflow.com/questions/5698148/where-does-the-gitignore-file-belong

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!