如何gitignore去二进制文件? [英] How to gitignore Go binaries?

查看:376
本文介绍了如何gitignore去二进制文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 .gitignore 这样的文件:

 #没有二进制文件
* /
!*。go /
!.gitignore

我认为 * / 表示忽略所有子目录中的所有文件(所以每个文件),!*。go / 意味着不要忽略所有子目录中的所有 *。go 文件,并且!。gitignore 意味着不要忽略的.gitignore 。然而,我现在的问题是,当我在子目录中创建一个新的 *。go 文件时,它现在被忽略了。



如何正确gitignore所有已编译的二进制文件,但不会忽略 *。go 文件?



我现在有

  ** / * 
!** / * .go
!.gitignore

但它仍然忽略ch1中的所有* .go文件目录。任何人都有想法?

解决方案

您需要使用:

 ** / *。go 

** 用于忽略任何文件夹内的文件,而不仅仅在当前文件夹中。




在git v2.7中修复了一个小错误:
$ b


允许稍后!/ abc / def

code>来覆盖之前的 / abc ,即
出现在相同的 .gitignore 文件,以便于表达

/ abc目录中的所有内容都会被忽略,除了...



$ .gitignore 文档:


连续两个星号( **



<$> 在与完整路径名相匹配的模式中可能具有特殊含义: c $ c> Leading **




领先的** ,后面跟着斜杠表示匹配所有目录

例如, ** / foo 匹配文件或目录 foo 任意,与 foo

** / foo / bar 与目录 foo



尾随**




尾随/ ** 里面

例如, abc / ** 目录中的所有文件匹配目录 abc ,相对于 .gitignore 文件的位置,具有无限深度。


blockquote>

/ ** /




斜线后跟 2连续的星号,则斜线匹配零个或多个目录。

例如, a / ** / b 匹配 a / b a / x / b a / x / y / b 等等。



I have a .gitignore file like this:

# no binaries
*/
!*.go/
!.gitignore

I thought */ means to ignore all files in all subdirectories (so every file), !*.go/ means to not-ignore all *.go files in all subdirectories, and !.gitignore means to not ignore .gitignore.

However, the issue I have now is that when I create a new *.go file in a subdirectory, it's now ignored.

How do I correctly gitignore all compiled binaries, but not ignore *.go files?

I now have

**/*  
!**/*.go
!.gitignore

But it still ignores all *.go files in the ch1 directory. Anyone else have ideas?

解决方案

You need to use:

**/*.go

The ** is for ignoring files inside any folder and not only in the current folder.


A minor bug was fixed in git v2.7:

Allow a later !/abc/def to override an earlier /abc that
appears in the same .gitignore file to make it easier to express
everything in /abc directory is ignored, except for ....


From the .gitignore documentation:

Two consecutive asterisks (**) in patterns matched against full pathname may have special meaning:

Leading **

A leading ** followed by a slash means match in all directories.
For example, **/foo matches file or directory foo anywhere, the same as pattern foo.
**/foo/bar matches file or directory "bar" anywhere that is directly under directory foo.

Trailing **

A trailing /** matches everything inside.
For example, abc/** matches all files inside directory abc, relative to the location of the .gitignore file, with infinite depth.

/**/

A slash followed by two consecutive asterisks then a slash matches zero or more directories.
For example, a/**/b matches a/b, a/x/b, a/x/y/b and so on.

这篇关于如何gitignore去二进制文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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