Reputation: 10203
In order to create an automatic release notes tool, I created a script listing all commits between two tags. But in some case, the tools list more commits than I wanted.
For example, with the following graph :
* abc123 [v42] Merge branch foo on branch bar
|\
* | def465 ...
* | fba602 ...
| * da07b4 ...
* | 98dc92 [v41] ...
In this case, I want to list the commits directly between v41 and v42. I tried with git log v41..v42
and git log v41...v42
(as suggested by codeWizard) but git also includes the commit da07b4
which is not a children of v41.
Upvotes: 2
Views: 1909
Reputation: 142084
You can always use the ..
(known as range
).
git log [first commit]..[second commit ] --pretty=oneline
This will show you all the commits in the given range.
..
to ...
git log a..b
means give me all commits that were made since a
, until and including b
(or, like the man page puts it "Include commits that are reachable from b but exclude those that are reachable from a"), the three-dot variant
git log a...b
means "Include commits that are reachable from either a or b but exclude those that are reachable from both", which is a totally different thing.
Upvotes: 4
Reputation: 10203
As stated in this answer,
"Between" is a somewhat slippery notion, when it comes to git commits.
In my case, I wanted to be sure to ignore commits which were not children of the first tag. here's the script i used, with the help of the git merge-base
command which finds the nearest merge base ancestor.
#!/bin/bash
base_hash=`git log --format=%H -1 $1`
# list all commits between start and end of a version
git log --format="%H" $1^..$2 | while read commit_hash; do
# check if this commit is reeaaaaally part of the release note
merge_base=`git merge-base $1 ${commit_hash}`
if [ "${merge_base}" = "${base_hash}" ]; then
# profit
fi
done
Upvotes: 2