全局 Git 忽略 [英] Global Git ignore

查看:38
本文介绍了全局 Git 忽略的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想设置 Git 以全局忽略某些文件.

I want to set up Git to globally ignore certain files.

我已将 .gitignore 文件添加到我的主目录 (/Users/me/) 并添加了以下行:

I have added a .gitignore file to my home directory (/Users/me/) and I have added the following line to it:

*.tmproj

但它并没有忽略这种类型的文件,知道我做错了什么吗?

But it is not ignoring this type of files, any idea what I am doing wrong?

推荐答案

您需要设置全局 core.excludesfile 配置文件以指向该全局忽略文件,例如:

You need to set up your global core.excludesfile configuration file to point to this global ignore file e.g:

*nix 或 Windows git bash:

git config --global core.excludesFile '~/.gitignore'

Windows cmd:

git config --global core.excludesFile "%USERPROFILE%.gitignore"

Windows PowerShell:

git config --global core.excludesFile "$Env:USERPROFILE.gitignore"

对于 Windows,它设置为位置 C:Users{myusername}.gitignore.您可以通过执行以下操作来验证配置值是否正确:

For Windows it is set to the location C:Users{myusername}.gitignore. You can verify that the config value is correct by doing:

git config --global core.excludesFile

结果应该是您的用户配置文件 .gitignore 的扩展路径.确保该值不包含未扩展的 %USERPROFILE% 字符串.

The result should be the expanded path to your user profile's .gitignore. Ensure that the value does not contain the unexpanded %USERPROFILE% string.

重要:以上命令只会设置git将使用的忽略文件的位置.该文件仍必须在该位置手动创建并填充忽略列表.(来自 muruge 的评论)

Important: The above commands will only set the location of the ignore file that git will use. The file has to still be manually created in that location and populated with the ignore list. (from muruge's comment)

您可以在 https://help.github.com/articles/ignoring-files/#create-a-global-gitignore

这篇关于全局 Git 忽略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆