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 tree information


It can sometimes be useful to show or find information on certain trees and files in Git. Here, the ls-tree and diff-tree commands come in handy. Essentially, these are plumbing commands, and they can sometimes be very useful when scripting or browsing.

Getting ready

We'll use the same repository as the previous example:

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

We also need a bare repository for some examples; it will by default, with the --bare option, be cloned to data-model.git, so remember which repository you are currently working on:

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

How to do it...

To show the content of the current tree in the Git context, we can use the ls-tree command. We'll pass --abbrev to the command to limit the SHA-1 ID to its abbreviated form. This is usually seven characters:

$ git ls-tree --abbrev HEAD
100644 blob f21dc28  README.md
040000 tree abc267d  a_sub_directory
100644 blob b50f80a...