Skip to Content
Git: Mastering Version Control
book

Git: Mastering Version Control

by Ferdinando Santacroce, Aske Olsson, Rasmus Voss, Jakub Narębski
October 2016
Beginner
861 pages
20h 37m
English
Packt Publishing
Content preview from Git: Mastering Version Control

Displaying the repository information

It is fairly common to have some scripts that use repository information, for example, builds or release note generation. This small example will show some examples of the rev-parse command that can be very useful for scripting.

Getting ready

Clone the data-model repository from Chapter 1, Navigating Git:

$ git clone https://github.com/dvaske/data-model.git
$ cd data-model

How to do it...

First, let's figure out the ID of the commit at HEAD:

$ git rev-parse HEAD
34acc370b4d6ae53f051255680feaefaf7f7850d

This can, of course, also be obtained by git log -1 --format=%H, but with the rev-parse command, you don't need all the options. We can also get the current branch from the rev-parse command:

$ git rev-parse --symbolic-full-name ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Git Version Control Cookbook - Second Edition

Git Version Control Cookbook - Second Edition

Kenneth Geisshirt, Emanuele Zattin(EUR), Aske Olsson, Rasmus Voss
Git Pocket Guide

Git Pocket Guide

Richard E. Silverman

Publisher Resources

ISBN: 9781787123205Supplemental Content