Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
410 views
in Technique[技术] by (71.8m points)

git - 全局Git忽略(Global Git ignore)

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

(我想将Git设置为全局忽略某些文件。)

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

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

*.tmproj

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

(但这不是没有忽略这种类型的文件,你知道我在做什么错吗?)

  ask by Mild Fuzz translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

(您需要设置全局core.excludesfile文件配置文件以指向此全局忽略文件。)

eg

(例如)

*nix or Windows git bash:

(* nix或Windows git bash:)

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

Windows cmd:

(Windows cmd:)

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

Windows PowerShell:

(Windows PowerShell:)

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

For Windows it set to the location C:\Users\{myusername}\.gitignore .

(对于Windows,将其设置为位置C:\Users\{myusername}\.gitignore 。)

You can verify that the config value is correct by doing:

(您可以通过执行以下操作来验证配置值是否正确:)

git config --global core.excludesfile

The result should be the expanded path to your user profile's .gitignore .

(结果应该是用户配置文件.gitignore的扩展路径。)

Ensure that the value does not contain the unexpanded %USERPROFILE% string.

(确保该值不包含未扩展的%USERPROFILE%字符串。)

The above commands will only set the location of the ignore file that git will use.

(上面的命令只会设置git将使用的忽略文件的位置。)

The file has to still be manually created in that location and populated with the ignore list.(from muruge 's comment)

(该文件仍必须在该位置手动创建并用忽略列表填充。(来自muruge的评论))

You can read about the command at https://help.github.com/articles/ignoring-files/#create-a-global-gitignore

(您可以在https://help.github.com/articles/ignoring-files/#create-a-global-gitignore中阅读有关命令的信息)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...