[英]staging all files except specific files using glob patterns in git
I am trying to stage some new created files and some others edited files to my staging area in git using git add command. 我正在尝试使用git add命令将一些新创建的文件以及其他一些已编辑的文件暂存到git的暂存区中。 What I exactly want is to stage everything except *.java files (in my current directory and in every sub directory in my project).
我真正想要的是暂存除* .java文件之外的所有文件(在我的当前目录和项目中的每个子目录中)。 I tried to get that work with NO success.
我试图使这项工作没有成功。
pwd: /d/myProject pwd:/ d / myProject
Nothing of these worked: 这些都不起作用:
git add !(*.java)
git add \!\(\*.java\)
git add \!\(*.java\)
git add !\(\*.java\)
Could somebody help me to get that work please? 有人可以帮我做那个工作吗? And is it somehow possible to use regular expressions instead of globs here?
并且在某种程度上可以使用正则表达式代替glob吗?
You could use find
: 您可以使用
find
:
find . -type f ! -iname '*.java' -exec git add {} +
You can also skip paths matching a pattern by using ! -ipath <pattern>
您也可以使用
! -ipath <pattern>
跳过与模式匹配的路径! -ipath <pattern>
! -ipath <pattern>
, eg: ! -ipath <pattern>
,例如:
find . -type f ! -iname '*.java' ! -ipath './a/b/*c*' -exec git add {} +
This really depends on the glob settings of your shell. 这实际上取决于外壳程序的glob设置。 What you can do for have a more system-independent behavior is to use find:
对于更独立于系统的行为,您可以做的是使用find:
find . -not -iname '*.java' -exec git add '{}' \+
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.