git添加与模式不匹配的文件 [英] Git add files which do not match a pattern

查看:87
本文介绍了git添加与模式不匹配的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Git中,将文件添加到提交中时,我们可以添加所有与模式匹配的文件,如下所示:

In Git, while adding files to a commit, we can add all files matching a pattern like so:

git add ** Component **

我发现此功能非常有用,可以快速添加许多具有相似名称的文件.

I find this feature pretty useful to quickly add lots of files with similar names.

例如,如果我的所有文件都基于组件命名,那么我可以快速将对组件所做的所有更改添加到组件中.

For example, If all my files are named based on components, then I can add all changes I did to a component quickly.

类似地,git中是否可以添加所有文件以提交排除匹配模式的文件?

Similarly, is there a way in git to add all files to commit excluding files matching a pattern?

类似的东西:

git add * .java --exclude ** Component1 **

这样我就可以对我的所有java文件进行更改,除了对component1的文件所做的更改之外?

So that I can all my java file changes except the changes that I made to the files of component1?

推荐答案

尝试以下方法之一

git add *.java ':(exclude):**Component1**'
git add *.java ':!**Component1**'

任何以冒号开头的pathspec都是魔术路径规范. exclude 是其中之一.

Any pathspec beginning with a colon is a magic pathspec. exclude is one of them.

这篇关于git添加与模式不匹配的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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