Where does the .gitignore file belong?

2019-01-29 16:42发布

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

标签: git gitignore
7条回答
Bombasti
2楼-- · 2019-01-29 16:52

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楼-- · 2019-01-29 16:54

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

查看更多
爷的心禁止访问
4楼-- · 2019-01-29 16:59

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

$ ls -1d .git*
.git
.gitignore
查看更多
5楼-- · 2019-01-29 17:11

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.

查看更多
我想做一个坏孩纸
6楼-- · 2019-01-29 17:13

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.

查看更多
forever°为你锁心
7楼-- · 2019-01-29 17:15

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)

查看更多
登录 后发表回答