Displaying file at a given git revision

git show can be used to display

  • All changes done at a given revision
  • Changes done to a given file
  • File at a given revision

Let’s see the difference. Diff has been shortened for the sake of simplicity.

All changes done at a given revision

git show 63745fb
────────────────────────────────────
modified: Gemfile
────────────────────────────────────

+ gem 'doorkeeper-jwt'
gem 'jsonapi-resources'
────────────────────────────────────
modified: Gemfile.lock
────────────────────────────────────

+ doorkeeper-jwt (0.1.6)
+   jwt (~> 1.5.2, >= 1.5.2)
erubis (2.7.0)

Changes done to a given file

git show 63745fb Gemfile
────────────────────────────────────
modified: Gemfile
────────────────────────────────────

+ gem 'doorkeeper-jwt'
gem 'jsonapi-resources'

File at a given revision

git show 63745fb:Gemfile
source 'https://rubygems.org'

gem 'rails', '~> 5.0.0'
gem 'puma', '~> 3.0'

gem 'doorkeeper'
gem 'doorkeeper-jwt'
gem 'jsonapi-resources'

Displaying file at a given revision can be used in vim to insert the output from git show 63745fb:Gemfile to the current buffer. Sometimes it is helpful when resolving git conflicts.

r !git show 63745fb:Gemfile

Thanks for reading!
This protip has been written in 1167 seconds