User Tools

Site Tools


git_revisions

This is an old revision of the document!


Overview

A small sample of Git revisions; different ways to refer to commits (using Linux kernel source repo).

Basic Git revisions

HEAD (commonly the default) refers to the commit at the tip of the current branch:

$ git show
$ git show HEAD

Commits are also reflected in branch or tag names:

$ git show master
$ git show v4.16

And of course you can always use the full commit ID (or a sufficient prefix):

$ git show 0adb32858b0bddf4ada5f364a84ed60b196dbcda
$ git show 0adb32858b0

You can use git rev-parse to map a reference to its underlying commit ID:

$ git rev-parse v4.16
3fb78e8be9d9428fbc4c016f8b031b01a6fdd63d
$

Ancestral Git revisions/references

Given any revision, you can refer to its (first) parent, or first grandparent, and so on:

$ git show HEAD
$ git show HEAD^         (first parent)
$ git show HEAD^^        (first grandparent)
$ git show master^       (master's first parent)
$ git show v4.16^^^      (v4.16's first great-grandparent)

There's also the tilde notation for brevity, so these are (ignoring intermediate merge commits) equivalent:

$ git show v4.16^^^
$ git show v4.16~3

Examples using git diff:

$ git diff v4.16^^ v4.16^
$ git diff v4.16^ v4.16

Commits with more than one parent

First or second parent:

$ git show HEAD^
$ git show HEAD^2
git_revisions.1552909395.txt.gz · Last modified: 2019/03/18 11:43 by rpjday