Mohsen Laali Mohsen Laali - 18 days ago 6
Git Question

git show on a sepecific file return 'fatal: bad object'

I am using git show to retrieve a file content on a specific revision of elasticsearch which is hosted in Github. This is my git command which I run at root of the project:

git show 63cbc8439357f496ce630c2eb35b2cf02342fa4b~1:rest-spec

However, I received following error:

fatal: bad object 63cbc8439357f496ce630c2eb35b2cf02342fa4b~1:rest-spec

The rest-spec is existed in the version 63cbc8439357f496ce630c2eb35b2cf02342fa4b~1 since, it is changed in the next revision. You can see the change of the next revision here in Github and I verified it with my local clone with the following command:

git show 63cbc8439357f496ce630c2eb35b2cf02342fa4b

This is output of above git show (I just include the change of rest-spec):

diff --git a/rest-spec b/rest-spec
deleted file mode 160000
index b3ab724..0000000
--- a/rest-spec
+++ /dev/null
@@ -1 +0,0 @@
-Subproject commit b3ab72486fae1b5c5a5397356a3e113bf72eb6d5

Highly appreciate your help!


That's because rest-spec is a submodule of the elasticsearch repository and, thus, is not an object belonging to (directly stored in) that repository. Look at the tree of the 63cbc8439357f496ce630c2eb35b2cf02342fa4b~1 revision to make sure that rest-spec is different from other objects. It is recorded in the elasticsearch repository through the .gitmodules file, and the contents of the referenced repository elasticsearch-rest-api-spec are made available as a subdirectory in the working tree of the superproject (i.e. the elasticsearch repository) via the git submodule commands. For more details see the Submodules chapter in the Git Book and the documentation of the git submodule command.