How to use `git log –first-parent` to only view commits that happened on a given branch – 077

First Parent Only via Visual Studio – View History

By default the View History option in Visual Studio (from Changes – Action – View History or from the Status bar  – <branch name> – View History) shows all commits, regardless whether the commit occurred in a separate branch or on the current branch. Let’s assume master is the current branch for simplicity. I’m using Open Live Writer as an example.

Shout out to http://marcgg.com/blog/2015/08/04/git-first-parent-log/ who has a great write-up on when you’d use –first-parent.

Right now on Twitter, developers are sharing how much they have to look up things. “Hi, my name is Sara. When I look at the Git history graph, I see a praying mantis.”

local history for master branch showing crazy graph

If you only want to see the changes that occurred on master (or whatever branch you are currently viewing the history for), you can click the Show First Parent Only button.

Show First Parent Only

Now you’ll only see commits that occurred directly on the branch itself (and not on another branch that got merged into the current branch).

Local History now a flat graph

Command Line git log –first-parent

Rinse and repeat for command line.

From yesterday’s tip, if you run git log –graph –pretty=oneline –graph –abbrev-commit

git log --graph --pretty=oneline --graph --abbrev-commit

You’ll see all of the commits from different branches.

Now add the –first-parent option at the end: git log –graph –pretty=oneline –graph –abbrev-commit –first-parent

git log --graph --pretty=oneline --graph --abbrev-commit --first-parent

Thanks again to http://marcgg.com/blog/2015/08/04/git-first-parent-log/ for the great description! As I said above, I just see a praying mantis. 🙂

One thought on “How to use `git log –first-parent` to only view commits that happened on a given branch – 077

  1. This deep/lateral/hail-mary cruising of Git is fascinating, although my eyes cross painfully when I gaze upon the captures of cmd/bash-foo shell outputs. Thanks for tying these into the VS presentations and how they work. I confess that the intricacies of git-foo do encourage me to keep project structures dead simple, and I suspect that is a good thing for my purposes around coding in the open.

    Like

Leave a comment