Categories
DailyOps

How to get a better overview of a particular git branch

Get a better overview of a particular git branch.

Clone a sample repository that will be used in this example.

$ git clone https://github.com/milosz/git-first-parent-example.git
Cloning into 'git-first-parent-example'...
remote: Enumerating objects: 18, done.
remote: Counting objects: 100% (18/18), done.
remote: Compressing objects: 100% (7/7), done.
remote: Total 18 (delta 5), reused 18 (delta 5), pack-reused 0
Unpacking objects: 100% (18/18), 1.75 KiB | 596.00 KiB/s, done.

Change working directory.

$ cd git-first-parent-example

Display commit logs.

$ git log
commit f66f13553d68e295bf77a1b04ca5d5242180558a (HEAD -> master, origin/master, origin/HEAD)
Merge: d70f303 f43266b
Author: Milosz Galazka <milosz@sleeplessbeastie.eu>
Date:   Tue Jun 1 20:59:45 2021 +0200

    Merge branch 'TRACK-6850'

commit d70f303c6ae4de4766131ba3c7c802452faa2e58
Merge: 726961d c679056
Author: Milosz Galazka <milosz@sleeplessbeastie.eu>
Date:   Tue Jun 1 20:59:45 2021 +0200

    Merge branch 'TRACK-4320'

commit f43266b5f72e9643608ca5768a7268678facf123
Author: Milosz Galazka <milosz@sleeplessbeastie.eu>
Date:   Tue Jun 1 20:59:45 2021 +0200

    added script.sh

commit 726961d5d609e7e4b26e3bea54244c374a7b6450
Merge: 138036d bc0e342
Author: Milosz Galazka <milosz@sleeplessbeastie.eu>
Date:   Tue Jun 1 20:59:45 2021 +0200

    Merge branch 'TRACK-1250'

commit c6790565ce1193ea130f28fbe4b04fdff25d756d
Author: Milosz Galazka <milosz@sleeplessbeastie.eu>
Date:   Tue Jun 1 20:59:45 2021 +0200

    updated readme file

commit 138036d9f244edc19f994a56ac2eaa9c0fdad0a7
Author: Milosz Galazka <milosz@sleeplessbeastie.eu>
Date:   Tue Jun 1 20:59:45 2021 +0200

    initial import

commit bc0e3421badd463fef097cf9147feb1bbac5e69b
Author: Milosz Galazka <milosz@sleeplessbeastie.eu>
Date:   Tue Jun 1 20:59:45 2021 +0200

    renamed readme.txt to readme.md

commit d57c560ddafadf2b409ddc28b33da4b232ff3308
Author: Milosz Galazka <milosz@sleeplessbeastie.eu>
Date:   Tue Jun 1 20:59:45 2021 +0200

    added initial header

Display text-based graphical representation of the commit history.

$ git log --graph
*   commit f66f13553d68e295bf77a1b04ca5d5242180558a (HEAD -> master, origin/master, origin/HEAD)
|\  Merge: d70f303 f43266b
| | Author: Milosz Galazka <milosz@sleeplessbeastie.eu>
| | Date:   Tue Jun 1 20:59:45 2021 +0200
| | 
| |     Merge branch 'TRACK-6850'
| | 
| * commit f43266b5f72e9643608ca5768a7268678facf123
| | Author: Milosz Galazka <milosz@sleeplessbeastie.eu>
| | Date:   Tue Jun 1 20:59:45 2021 +0200
| | 
| |     added script.sh
| |   
* |   commit d70f303c6ae4de4766131ba3c7c802452faa2e58
|\ \  Merge: 726961d c679056
| |/  Author: Milosz Galazka <milosz@sleeplessbeastie.eu>
|/|   Date:   Tue Jun 1 20:59:45 2021 +0200
| |   
| |       Merge branch 'TRACK-4320'
| | 
| * commit c6790565ce1193ea130f28fbe4b04fdff25d756d
|/  Author: Milosz Galazka <milosz@sleeplessbeastie.eu>
|   Date:   Tue Jun 1 20:59:45 2021 +0200
|   
|       updated readme file
|   
*   commit 726961d5d609e7e4b26e3bea54244c374a7b6450
|\  Merge: 138036d bc0e342
| | Author: Milosz Galazka <milosz@sleeplessbeastie.eu>
| | Date:   Tue Jun 1 20:59:45 2021 +0200
| | 
| |     Merge branch 'TRACK-1250'
| | 
| * commit bc0e3421badd463fef097cf9147feb1bbac5e69b
| | Author: Milosz Galazka <milosz@sleeplessbeastie.eu>
| | Date:   Tue Jun 1 20:59:45 2021 +0200
| | 
| |     renamed readme.txt to readme.md
| | 
| * commit d57c560ddafadf2b409ddc28b33da4b232ff3308
|/  Author: Milosz Galazka <milosz@sleeplessbeastie.eu>
|   Date:   Tue Jun 1 20:59:45 2021 +0200
|   
|       added initial header
| 
* commit 138036d9f244edc19f994a56ac2eaa9c0fdad0a7
  Author: Milosz Galazka <milosz@sleeplessbeastie.eu>
  Date:   Tue Jun 1 20:59:45 2021 +0200
  
      initial import

Display commit logs, but follow only the first parent commit upon seeing a merge commit.

$ git log --first-parent
commit f66f13553d68e295bf77a1b04ca5d5242180558a (HEAD -> master, origin/master, origin/HEAD)
Merge: d70f303 f43266b
Author: Milosz Galazka <milosz@sleeplessbeastie.eu>
Date:   Tue Jun 1 20:59:45 2021 +0200

    Merge branch 'TRACK-6850'

commit d70f303c6ae4de4766131ba3c7c802452faa2e58
Merge: 726961d c679056
Author: Milosz Galazka <milosz@sleeplessbeastie.eu>
Date:   Tue Jun 1 20:59:45 2021 +0200

    Merge branch 'TRACK-4320'

commit 726961d5d609e7e4b26e3bea54244c374a7b6450
Merge: 138036d bc0e342
Author: Milosz Galazka <milosz@sleeplessbeastie.eu>
Date:   Tue Jun 1 20:59:45 2021 +0200

    Merge branch 'TRACK-1250'

commit 138036d9f244edc19f994a56ac2eaa9c0fdad0a7
Author: Milosz Galazka <milosz@sleeplessbeastie.eu>
Date:   Tue Jun 1 20:59:45 2021 +0200

    initial import

Display text-based graphical representation of the commit history, but follow only the first parent commit upon seeing a merge commit.

$ git log --graph --first-parent
* commit f66f13553d68e295bf77a1b04ca5d5242180558a (HEAD -> master, origin/master, origin/HEAD)
| Merge: d70f303 f43266b
| Author: Milosz Galazka <milosz@sleeplessbeastie.eu>
| Date:   Tue Jun 1 20:59:45 2021 +0200
| 
|     Merge branch 'TRACK-6850'
| 
* commit d70f303c6ae4de4766131ba3c7c802452faa2e58
| Merge: 726961d c679056
| Author: Milosz Galazka <milosz@sleeplessbeastie.eu>
| Date:   Tue Jun 1 20:59:45 2021 +0200
| 
|     Merge branch 'TRACK-4320'
| 
* commit 726961d5d609e7e4b26e3bea54244c374a7b6450
| Merge: 138036d bc0e342
| Author: Milosz Galazka <milosz@sleeplessbeastie.eu>
| Date:   Tue Jun 1 20:59:45 2021 +0200
| 
|     Merge branch 'TRACK-1250'
| 
* commit 138036d9f244edc19f994a56ac2eaa9c0fdad0a7
  Author: Milosz Galazka <milosz@sleeplessbeastie.eu>
  Date:   Tue Jun 1 20:59:45 2021 +0200
  
      initial import

This is splendid.

Additional notes

Use the following script.sh to play with it.

#!/bin/bash

git init

touch readme.txt
git add readme.txt
git commit -m "initial import"

git checkout -b TRACK-1250 master
cat <<EOF | tee  readme.txt
# git first parent example
EOF
git add readme.txt
git commit -m "added initial header"
git mv readme.txt readme.md
git commit -m "renamed readme.txt to readme.md"

git checkout master
git merge --no-ff --no-edit TRACK-1250

git checkout -b TRACK-4320 master
cat <<EOF | tee  readme.md
# git first parent example
simple example to illustrate 'first-parent' option
EOF
git add readme.md
git commit -m "updated readme file"

git checkout -b TRACK-6850 master
cat <<EOF | tee script.sh
$(cat $0)
EOF
git add script.sh
git commit -m "added script.sh"

git checkout master
git merge --no-ff --no-edit TRACK-4320
git merge --no-ff --no-edit TRACK-6850

Excerpt from the git-log manual page.

       --first-parent
           Follow only the first parent commit upon seeing a merge commit. This option can give a better overview when viewing the evolution of a
           particular topic branch, because merges into a topic branch tend to be only about adjusting to updated upstream from time to time, and this
           option allows you to ignore the individual commits brought in to your history by such a merge. Cannot be combined with --bisect.