{"thread":{"id":"33970","subject":"Retrieving a file at a before a specified commit","startedAt":"2013-05-29T06:47:35Z","lastAt":"2013-05-30T03:19:03Z","messageCount":8,"participants":["Erik de Castro Lopo","Jeff King","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"218774","messageId":"20130529164735.5489ab47953406745d9034ef@mega-nerd.com","threadId":"33970","inReplyTo":null,"subject":"Retrieving a file at a before a specified commit","fromName":"Erik de Castro Lopo","fromEmail":"mle+tools@mega-nerd.com","sentAt":"2013-05-29T06:47:35Z","receivedAt":"2013-05-29T06:47:35Z","isPatch":false,"sender":{"key":"mle+tools@mega-nerd.com","avatar":null},"body":"Hi all,\n\nI have a commit like this:\n\n    commit 4d77a3cee01db0412956d40875c79f51ac745acc\n    tree 3443c9f633114c3bd2e015453a8c55a171e62b53\n    parent 340d808ade8a79857bec40770f0eb4f98224c53d\n    author ....\n    committer .....\n\nwhich modifies file A/B/C (ie specifically does not add, but changes\nan existing file in the repo).\n\nI would then like to retrive the version of the file A/B/C before\ncommit 4d77a3cee by using the parent commit 340d808a:\n\n   git show 340d808ade8a79857bec40770f0eb4f98224c53d:A/B/C\n\nwhich works for most files/commits I try this with, but doesn't work\nin one particular case.\n\nQuestions:\n\n- Is my understanding of the above git command incorrect?\n- Is this a corrupt repo? Is there some way to check?\n- Is there some explaination of why I can't get the previous version\n  of that file?\n\nAppreciate any light that could be shed on this.\n\nCheers,\nErik\n-- \n----------------------------------------------------------------------\nErik de Castro Lopo\nhttp://www.mega-nerd.com/\n"},{"id":"218783","messageId":"20130529075811.GA7204@sigill.intra.peff.net","threadId":"33970","inReplyTo":"20130529164735.5489ab47953406745d9034ef@mega-nerd.com","subject":"Re: Retrieving a file at a before a specified commit","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2013-05-29T07:58:11Z","receivedAt":"2013-05-29T07:58:11Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Wed, May 29, 2013 at 04:47:35PM +1000, Erik de Castro Lopo wrote:\n\n> I have a commit like this:\n> \n>     commit 4d77a3cee01db0412956d40875c79f51ac745acc\n>     tree 3443c9f633114c3bd2e015453a8c55a171e62b53\n>     parent 340d808ade8a79857bec40770f0eb4f98224c53d\n>     author ....\n>     committer .....\n> \n> which modifies file A/B/C (ie specifically does not add, but changes\n> an existing file in the repo).\n> \n> I would then like to retrive the version of the file A/B/C before\n> commit 4d77a3cee by using the parent commit 340d808a:\n> \n>    git show 340d808ade8a79857bec40770f0eb4f98224c53d:A/B/C\n> \n> which works for most files/commits I try this with, but doesn't work\n> in one particular case.\n\nYes, that should work as long as the file is modified and not added. You\ncan also say \"4d77a3cee^:A/B/C\" if you do not want to look up the parent\nid yourself.\n\nNote that for a merge commit with multiple parents, the question is more\ncomplex, as there are two previous states that are merged.\n\nYou say that it doesn't work in one particular case. What is that case?\nWhat happens?\n\n> Questions:\n> \n> - Is my understanding of the above git command incorrect?\n\nNo, I think it is correct.\n\n> - Is this a corrupt repo? Is there some way to check?\n\nRunning \"git fsck\" can tell you if there is repository corruption.\n\n> - Is there some explaination of why I can't get the previous version\n>   of that file?\n\nProbably. Can you show us the commit that fails? What does git say when\nyou try it?\n\n-Peff\n"},{"id":"218915","messageId":"20130530104932.d7ba4bfb426044ab9653057e@mega-nerd.com","threadId":"33970","inReplyTo":"20130529075811.GA7204@sigill.intra.peff.net","subject":"Re: Retrieving a file at a before a specified commit","fromName":"Erik de Castro Lopo","fromEmail":"mle+tools@mega-nerd.com","sentAt":"2013-05-30T00:49:32Z","receivedAt":"2013-05-30T00:49:32Z","isPatch":false,"sender":{"key":"mle+tools@mega-nerd.com","avatar":null},"body":"Jeff King wrote:\n\n> Yes, that should work as long as the file is modified and not added. You\n> can also say \"4d77a3cee^:A/B/C\" if you do not want to look up the parent\n> id yourself.\n\nThanks, that's useful to know.\n\n> Note that for a merge commit with multiple parents, the question is more\n> complex, as there are two previous states that are merged.\n\nThis is not the case in the one I am currently looking at. There is a single\nparent commit.\n\n> You say that it doesn't work in one particular case. What is that case?\n> What happens?\n\nHere is an example. Grab this repository:\n\n    git clone git://github.com/qca/open-plc-utils.git\n    cd open-plc-utils/\n\nLook at this commit:\n\n    git log --name-status f51ac745a6d4087cc4d77a3cee01db0412955c79\n\nand notice that one of the files modified is \"pib/chkpib2.7\", so lets\nlook at the parent version of that file:\n\n    git show f51ac745a6d4087cc4d77a3cee01db0412955c79^:pib/chkpib2.7\n\nwhich produces no output and exits with 0 status.\n\nHowever looking at the diff for commit f51ac745a suggests that while\nthe file pib/chkpib2.7 may have existed before that commit, it must\nhave been empty (ie zero length).\n\nDoes this explanation make sense?\n\nErik\n-- \n----------------------------------------------------------------------\nErik de Castro Lopo\nhttp://www.mega-nerd.com/\n"},{"id":"218916","messageId":"20130530105956.dbf5e3363fa0abbc0143d463@mega-nerd.com","threadId":"33970","inReplyTo":"20130530104932.d7ba4bfb426044ab9653057e@mega-nerd.com","subject":"Re: Retrieving a file at a before a specified commit","fromName":"Erik de Castro Lopo","fromEmail":"erikd@mega-nerd.com","sentAt":"2013-05-30T00:59:56Z","receivedAt":"2013-05-30T00:59:56Z","isPatch":false,"sender":{"key":"erikd@mega-nerd.com","avatar":null},"body":"Erik de Castro Lopo wrote:\n\n> Does this explanation make sense?\n\nJust to answer my own question, Yes it does.\n\nThe file was added in commit 53266574 and was actually zero length\nat that time.\n\nCheers,\nErik\n----------------------------------------------------------------------\nErik de Castro Lopo\nhttp://www.mega-nerd.com/\n"},{"id":"218921","messageId":"7vobbtp5h5.fsf@alter.siamese.dyndns.org","threadId":"33970","inReplyTo":"20130530105956.dbf5e3363fa0abbc0143d463@mega-nerd.com","subject":"Re: Retrieving a file at a before a specified commit","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2013-05-30T02:27:18Z","receivedAt":"2013-05-30T02:27:18Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Erik de Castro Lopo <erikd@mega-nerd.com> writes:\n\n> Erik de Castro Lopo wrote:\n>\n>> Does this explanation make sense?\n>\n> Just to answer my own question, Yes it does.\n>\n> The file was added in commit 53266574 and was actually zero length\n> at that time.\n\nWhile you are at it, you may want to check your LESS environment\nvariable settings, especially if you find that the command gives you\ncontrol without showing anything for a small (not zero length) file.\n"},{"id":"218922","messageId":"20130530023446.GA19860@sigill.intra.peff.net","threadId":"33970","inReplyTo":"20130530104932.d7ba4bfb426044ab9653057e@mega-nerd.com","subject":"Re: Retrieving a file at a before a specified commit","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2013-05-30T02:34:46Z","receivedAt":"2013-05-30T02:34:46Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Thu, May 30, 2013 at 10:49:32AM +1000, Erik de Castro Lopo wrote:\n\n> Look at this commit:\n> \n>     git log --name-status f51ac745a6d4087cc4d77a3cee01db0412955c79\n> \n> and notice that one of the files modified is \"pib/chkpib2.7\", so lets\n> look at the parent version of that file:\n> \n>     git show f51ac745a6d4087cc4d77a3cee01db0412955c79^:pib/chkpib2.7\n> \n> which produces no output and exits with 0 status.\n> \n> However looking at the diff for commit f51ac745a suggests that while\n> the file pib/chkpib2.7 may have existed before that commit, it must\n> have been empty (ie zero length).\n> \n> Does this explanation make sense?\n\nYes, that is what I would expect git to do in such a situation. You can\ninspect it further, too:\n\n  $ git rev-parse f51ac745^:pib/chkpib2.7\n  e69de29bb2d1d6434b8b29ae775ad8c2e48c5391\n\nThat's the sha1 of the blob containing the content.  You can investigate\ninformation about that object like this:\n\n  $ git cat-file -t e69de29b\n  blob\n  $ git cat-file -s e69de29b\n  0\n  $ git cat-file blob e69de29b\n\nOf course since its size is 0, the last one is not that interesting. :)\n\nYou could also just look at the tree, which gives similar information:\n\n  $ git ls-tree -lr f51ac745^ | grep pib/chkpib2.7\n  100644 blob e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0 pib/chkpib2.7\n\nHope that helps.\n\n-Peff\n"},{"id":"218929","messageId":"20130530131821.594bc05666fa3ea17b55dffc@mega-nerd.com","threadId":"33970","inReplyTo":"7vobbtp5h5.fsf@alter.siamese.dyndns.org","subject":"Re: Retrieving a file at a before a specified commit","fromName":"Erik de Castro Lopo","fromEmail":"mle+tools@mega-nerd.com","sentAt":"2013-05-30T03:18:21Z","receivedAt":"2013-05-30T03:18:21Z","isPatch":false,"sender":{"key":"mle+tools@mega-nerd.com","avatar":null},"body":"Junio C Hamano wrote:\n\n> While you are at it, you may want to check your LESS environment\n> variable settings, especially if you find that the command gives you\n> control without showing anything for a small (not zero length) file.\n\nThanks. Thats a good tip. In my case LESS was not set to anything.\n\nCheers,\nErik\n-- \n----------------------------------------------------------------------\nErik de Castro Lopo\nhttp://www.mega-nerd.com/\n"},{"id":"218930","messageId":"20130530131903.d699bee16aa406790ea96a12@mega-nerd.com","threadId":"33970","inReplyTo":"20130530023446.GA19860@sigill.intra.peff.net","subject":"Re: Retrieving a file at a before a specified commit","fromName":"Erik de Castro Lopo","fromEmail":"mle+tools@mega-nerd.com","sentAt":"2013-05-30T03:19:03Z","receivedAt":"2013-05-30T03:19:03Z","isPatch":false,"sender":{"key":"mle+tools@mega-nerd.com","avatar":null},"body":"Jeff King wrote:\n\n> Yes, that is what I would expect git to do in such a situation. You can\n> inspect it further, too:\n> \n>   $ git rev-parse f51ac745^:pib/chkpib2.7\n>   e69de29bb2d1d6434b8b29ae775ad8c2e48c5391\n> \n> That's the sha1 of the blob containing the content.  You can investigate\n> information about that object like this:\n> \n>   $ git cat-file -t e69de29b\n>   blob\n>   $ git cat-file -s e69de29b\n>   0\n>   $ git cat-file blob e69de29b\n> \n> Of course since its size is 0, the last one is not that interesting. :)\n> \n> You could also just look at the tree, which gives similar information:\n> \n>   $ git ls-tree -lr f51ac745^ | grep pib/chkpib2.7\n>   100644 blob e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0 pib/chkpib2.7\n> \n> Hope that helps.\n\nYes it does. Thanks!\n\nErik\n-- \n----------------------------------------------------------------------\nErik de Castro Lopo\nhttp://www.mega-nerd.com/\n"}]}