0

I'm grepping code in git history using the following command:

git grep "foo" $(git rev-list --all)

It's returning a list where each line begins with a king of hash:

27a7c352c1d7e5fde63f7c8857900271abc0a626:LogsController.php: $foo = "Hello World!";
c70fab1b7b7e67734839855eff34d744ec1fbcd9:LogsController.php: $foo = "Hello World!";
28a7bfb582e903af5019e2e1eaa1587a7817ec1b:LogsController.php: $foo = "Hello World!";

How to view the original full file from one of these hashes ?

DevonDahon
  • 5,856
  • 3
  • 52
  • 74

1 Answers1

2

You are looking for :

git show 27a7c352c1d7e5fde63f7c8857900271abc0a626:Http/Controllers/LogsController.php

git show is mostly know for git show <commit-id>, which displays the information of a commit and its diff with its parent, but :

  • git show also displays the listing of directories ("trees" in git terms) and files ("blobs" in git terms),
  • there is a syntax to point to "a file or a directory within a commit", and that syntax is : <sha>:path/to/target

For example, try running :

# directories :
git show HEAD:
git show 27a7c352c1d7e5fde63f7c8857900271abc0a626:Http/Controllers/

# files :
git show HEAD:config.ini
git show 27a7c352c1d7e5fde63f7c8857900271abc0a626:Http/Controllers/LogsController.php
LeGEC
  • 35,975
  • 2
  • 46
  • 87