Git commit使用正则表达式还是globs?

时间:2015-06-05 17:14:46

标签: regex git glob

是否可以使用regular expressions,例如<script> $(document).ready(function(){ $(window).scroll(function () { $('#bar').css('top', $(document).scrollTop()); }); }); </script> <style> #bar { position: relative; } </style> #bar { width:900px; height:40px; display:inline-block; } <div id="bar"><input type="text" id="srch" name="srch"/></div>

我试过了,似乎只把它们解释为globs。我也厌倦了正则表达式旗帜:

git commit ".*my_file.*"

引发错误。

有没有人知道将正则表达式与Git命令结合的方法?

4 个答案:

答案 0 :(得分:1)

不是Git本身。 Git只接收从shell传递的文件列表,因此由shell来对文件进行正则表达式匹配。我不认为bash可以做到这一点,但其他shell可能会这样做。

答案 1 :(得分:1)

我能想到的最好方法是使用find命令。例如,如果您只想要python文件:

find -type f -regex ".*\.py$" -exec git commit {} -m "committing only and all python files" \;

其他人可以想到一些不那么笨重的东西吗?

答案 2 :(得分:0)

正如mipadi所提到的,shell可以生成参数以生成git的输入。

例如,ls可以组合使用。让我们说我有一个带有以下文件的git init-ed目录:

.git/
my_new_project_file.py
my_older_project_file.py
some_other_file.py

我想添加除some_other_file.py之外的所有内容。要做到这一点:

ls my*project*.py | xargs git add

检查我的git status会显示my_new_project_file.pymy_older_project_file.py已上演,而some_other_file.py已被忽略。

n.b。 ls不支持正则表达式;只是全球化。

答案 3 :(得分:0)

正如Candic3所指出的,git支持glob:

git add *my_file*