Git 忽略和 Maven 目标
任何人都知道是否可以忽略 git 管理的文件结构中特定目录的所有实例。
我希望排除具有多个子模块的 Maven 项目中的所有“目标”文件夹。 我知道我可以在顶级 .gitignore 中明确排除它们中的每一个,但我真的希望能够指定一个像 **/target/* 这样的模式,让它自动忽略子目录中的实例?
这可能吗?
Anyone know if it is possible to ignore all the instances of a particular directory in a file structure managed by git.
I'm looking to exclude all the 'target' folders in a maven project with a number of submodules. I know I can explicitly exclude each of them in a top level .gitignore, but I'd really like to be able to specify a pattern like **/target/* there to have it automatically ignore the instance in sub directories?
Is this possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
根目录中的 .gitignore 文件确实适用于所有子目录。 我的看起来像这样:
这是在一个多模块 Maven 项目中。 所有子模块均使用 m2eclipse 作为单独的 Eclipse 项目导入。 我没有更多的 .gitignore 文件。 事实上,如果您查看 gitignore 手册页:
所以这应该适合你。
The
.gitignore
file in the root directory does apply to all subdirectories. Mine looks like this:This is in a multi-module maven project. All the submodules are imported as individual eclipse projects using m2eclipse. I have no further
.gitignore
files. Indeed, if you look in the gitignore man page:So this should work for you.
可以在 .gitignore 文件中使用模式。 请参阅 gitignore 手册页。 模式
*/target/*
应忽略任何名为 target 的目录及其下的任何内容。 或者您可以尝试*/target/**
忽略 target 下的所有内容。It is possible to use patterns in a
.gitignore
file. See the gitignore man page. The pattern*/target/*
should ignore any directory named target and anything under it. Or you may try*/target/**
to ignore everything under target.正如 Abhijeet 的评论中已经指出的那样,您只需添加以下行即可:
到
\.git\info\
文件夹中的 排除 文件。然后,如果您想删除远程存储库中的
target
文件夹,您需要首先从本地存储库中手动删除该文件夹,提交然后推送它。 那是因为 git 会首先向您显示修改后的目标文件夹的内容。As already pointed out in comments by Abhijeet you can just add line like:
to exclude file in
\.git\info\
folder.Then if you want to get rid of that
target
folder in your remote repo you will need to first manually delete this folder from your local repository, commit and then push it. Thats because git will show you content of a target folder as modified at first.在 gitignore 中从所有不需要的文件中添加以下行
add following lines in gitignore, from all undesirable files
我忽略了 git 中目标文件夹中的所有类。
在打开的 .gitignore 文件中添加以下行:
/.class
或
*/target/**
它非常适合我。 尝试一下。
I ignore all classes residing in target folder from git.
add following line in open .gitignore file:
/.class
OR
*/target/**
It is working perfectly for me. try it.
对于
Spring Tool Suite
,将以下忽略资源添加到.gitignore
文件中并提交到存储库中For the
Spring Tool Suite
, Add the following ignore resources to.gitignore
file and commit into the repository对于多模块存储库,除了 @Gleidosn 答案之外,我还会添加以下表达式以考虑嵌套目标文件夹:
For multi-module repositories, in addition to @Gleidosn answer I would add the following expression to take into consideration the nested target folders: