如何比较两个git分支并通过提交消息过滤差异? [英] How to compare two git branches and filter the differences by commit message?
问题描述
我有一个名为 release / X.X.X.X
的发布分支,其中包含我要部署到产品的所有功能分支。发布分支位于当前生产状态 master
之上
在每个发布日确保我们的发行版分支仅包含计划发布的更改。我使用这个命令来比较发行版和主分支: git log release / X.X.X.X ^ master --no-merges
。然后,我手动检查提交的关键字,如SHR-1234,它们代表票证管理系统中的票号。我需要将每个提交与一个票号列表进行比较,以识别不需要的更改。
如何筛选由 git log release返回的提交/ XXXX ^ master --no-merges
和不包含
我尝试了grep和awk,但结果并不有用,因为它们不会过滤掉整个提交。 / p>
git log
命令提供了两个有趣的选项:
- grep =< pattern>
  ;将提交输出限制为符合
指定模式(正则表达式)的日志消息。使用多于
- grep =< pattern>
的提交,其提交的消息匹配任何给定的
模式(但请参阅- 全部匹配
)。
  ;&NBSP;&NBSP;&NBSP;&NBSP;当
- show-notes
有效时,来自记事的消息是
,就好像它是日志消息的一部分一样。
因此 - grep
可以让您找到提交包含一些特定的字符串或模式。您希望提交的不包含(任何或所有)字符串,因此我们继续:
- invert-grep
将提交输出限制为日志消息与
不匹配的模式,该模式使用- grep =< pattern>
指定。 (顺便提一句,请注意,release / XXXX ^ master
也可以拼写成:master..release / XXXX
。没有机器级别的理由可以选择比其他机器级别更理想的方式 - 既可以在内部完成同样的事情 - 也可以使用任何更易读的。)I have a release branch named
release/X.X.X.X
which contains all feature branches I want to deploy to production. The release branch is made on top ofmaster
which is the current state of production.On every release day I make sure our release branch contains only those changes planned for the release. I use this command to compare the release and master branch:
git log release/X.X.X.X ^master --no-merges
. I then manually check the commits for keywords like "SHR-1234" which represent ticket numbers in our ticket management system. I need to compare each commit with a list of ticket numbers to identify unwanted changes.How can I filter commits that are returned by
git log release/X.X.X.X ^master --no-merges
and do not contain keywords like "SHR-1234"? This way I can identify the ticket number of unwanted changes.I tried grep and awk but the results are not useful because they don't filter out the whole commit.
解决方案The
git log
command provides two interesting options here:
--grep=<pattern>
Limit the commits output to ones with log message that matches the specified pattern (regular expression). With more than one--grep=<pattern>
, commits whose message matches any of the given patterns are chosen (but see--all-match
).When
--show-notes
is in effect, the message from the notes is matched as if it were part of the log message.Hence
--grep
lets you find commits that do contain some particular string or pattern. You want commits that do not contain (any or all) strings, so we move on to:
--invert-grep
Limit the commits output to ones with log message that do not match the pattern specified with--grep=<pattern>
.(Incidentally, note that
release/X.X.X.X ^master
can also be spelledmaster..release/X.X.X.X
. There's no machine-level reason to prefer one over the other—both wind up doing exactly the same thing internally—so use whichever you find more readable.)这篇关于如何比较两个git分支并通过提交消息过滤差异?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!