如果我确定$1
的{{1}}没有特殊字符,我可以找到消息等于$1
的提交
我可以忽略特殊字符,并使用git log --grep "^${1}$"
搜索包含模式的字符串
我想要一个bash函数,该函数返回所有提交
完全具有提交消息git log --fixed-strings --grep "$1"
$1
如果get_commits_by_message() {
echo git log --format=%H ... $1;
}
包含特殊字符,如何获取消息等于$1
的提交哈希值?
答案 0 :(得分:1)
[edit]如果要找出从A
到B
精心挑选的提交,请尝试:
git log --graph --oneline --boundaries --cherry-mark A...B # 3 dots
--cherry-mark
将标记带有=
的在两侧带来相同更改的提交。
如果将--cherry-mark
替换为--cherry-pick
,则匹配的提交将被完全隐藏,并且您可以比较其余提交的消息以查看它们是否已被重播但已被修改(以解决冲突。例如)。
[原始答案]
a。编写一个函数(或脚本),将带有特殊字符的输入字符串转换为转义的形式
例如:将\ . [ ] * ^ $
变成\\ \. \[ \] \* \^ \$
(我可能会忘记一些其他特殊字符)
并在您的git log
命令中使用它:
# example for single line patterns :
rescape () { echo "$1" | sed -e 's/\([\^\[$.*]\)/\\\1/g' -e 's/]/\\]/g'; }
git log --grep "^$(rescape 'I can grep * and . and [ and ] !')$"
b。 (从技术上讲并不精确,但是在大多数情况下应该可以使用)如果您想要一种快速的方式来手动键入消息,请用.
替换任何特殊的字符:
# instead of grepping for :
^[1234] expand . to *$
# grep for :
^.1234. expand . to .$