How to compare two git branches and filter the differences by commit message?

霸气de小男生 提交于 2019-12-02 12:26:00

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 spelled master..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.)

you can use –G ‘regular expression’ to meet your requirement

git log release/X.X.X.X ^master--no-merges -G ‘regular expression’ (include or exclude the specified commit)

The question title admits a slightly different answer, which could be useful to some people. A simple way to compare two branches by commit title only is to dump commit titles from each branch to a separate text file, and open these two files in a diff viewer:

git --no-pager log --pretty=format:%s master > log_master.txt
git --no-pager log --pretty=format:%s other > log_other.txt
meld log_master.txt log_other.txt

We first dump commit subjects from branch master to the file log_master.txt, then commit subjects from branch other to the file log_other.txt, and open them in the visual diff viewer meld (one alternative is kdiff3).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!