2020-04-18 The main line of history of some branch

Some time ago, it occurred to me that it would be cool to be able to see the history of some branch of my Git repository – say, develop – but filtered so that I could only see the commits done directly on develop (which do not happen very often) and merge commits indicating that some feature got merged into develop, but without the individual commits. This could then serve as a poor man’s changelog - a list of features committed to develop.

In other words, I’d like to traverse the history in a “linear” way, selecting only the first parent of every merge. (I assume here that I never merge develop into some feature branch and then fast-forward – but this is easy to avoid, you just have to say git merge --no-ff when merging anything into develop; merging pull requests on BitBucket, which we use, does it exactly this way.)

And guess what? Git can do it. It is enough to say e.g. git log --first-parent --oneline and you have a concise history of all features merged into develop, together with all tags put on it. Great!

Of course, it would be even more useful if I could just list the commits starting with the first one after the last version. This can be accomplished in a number of ways, depending on the exact workflow. For instance, in the project I’m involved in, every new version is marked by a commit whose message is of the form 1.23.4 or similar (the version number). Such commits can be easily found using the :/ syntax, so I can say

git log --first-parent --oneline develop ^:/[0-9]+\\.[0-9]+\\.[0-9]+

Another way would be to look up commits until the first encountered tagged commit. This is easy to accomplish using the git describe command:

git log --first-parent --oneline develop ^$(git describe develop --abbrev=0)

Happy gitting!

CategoryEnglish, CategoryBlog, CategoryGit