Book Image

Git Version Control Cookbook

By : Aske Olsson, Rasmus Voss
Book Image

Git Version Control Cookbook

By: Aske Olsson, Rasmus Voss

Overview of this book

Table of Contents (19 chapters)
Git Version Control Cookbook
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

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 HEAD
refs/heads/master 

We can also just get the abbreviated name:

$ git rev-parse --symbolic-full-name --abbrev-ref HEAD
master

We can also get the ID of other refs:

$ git rev-parse origin/feature/2
82cd5662900a50063ff4bb790539fe4a6d470d56...