全局.gitignore
The .gitignore
file is cherished by developers because it can keep repositories clean after build files and OS-generated files (like .DS_Store
) clutter the structure of your repository. What I find is that I'm constantly adding the same files and directories (like node_modules
) to every repository and I find it tedious. I was hoping there was a way to globally ignore those files and directories ... and I've found it.
.gitignore
文件是开发人员所.gitignore
文件,因为它可以在构建文件和OS生成的文件(例如.DS_Store
)使您的存储库结构混乱之后使存储库保持干净。 我发现,我不断地向每个存储库添加相同的文件和目录(例如node_modules
),并且发现它很乏味。 我希望有一种全局忽略这些文件和目录的方法……我已经找到了。
You can create your global .gitignore
with this magic:
您可以使用以下魔术创建全局.gitignore
:
# Declare the global .gitignore
git config --global core.excludesfile ~/.gitignore_global
# Create the .gitignore_global file
touch .gitignore_global
# Go into edit mode so you can add the unwanted file listing
vim .gitignore_global
The snippet above creates a .gitignore_global
in your user directory which is respected throughout your user directory. Now you don't have to explicitly, repeatedly add the same files and directories to individual .gitignore
files! Excellent!
上面的代码段在您的用户目录中创建了一个.gitignore_global
在整个用户目录中都受到尊重。 现在,您不必显式地将相同的文件和目录重复添加到单个.gitignore
文件中! 优秀的!
This shouldn't be considered a great solution for collaborative repositories though -- someone else will inadvertently submit unwanted files and directories because the repo's own .gitignore
doesn't contain the unwanted file listing. For your own purposes, however, a global .gitignore
is aces!
但是,这不应被认为是协作存储库的理想解决方案-他人会无意中提交不需要的文件和目录,因为存储库自己的.gitignore
不包含不需要的文件列表。 但是,出于您自己的目的,全局.gitignore
是ace!
全局.gitignore