{"thread":{"id":"26530","subject":"How to git checkout a orgin(unstage) version file in another directoy?","startedAt":"2011-02-17T07:00:42Z","lastAt":"2011-02-18T07:41:50Z","messageCount":11,"participants":["Chunlin Zhang","Michael J Gruber","Jonathan Nieder","Andreas Schwab","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"161381","messageId":"loom.20110217T074533-358@post.gmane.org","threadId":"26530","inReplyTo":null,"subject":"How to git checkout a orgin(unstage) version file in another directoy?","fromName":"Chunlin Zhang","fromEmail":"zhangchunlin@gmail.com","sentAt":"2011-02-17T07:00:42Z","receivedAt":"2011-02-17T07:00:42Z","isPatch":false,"sender":{"key":"zhangchunlin@gmail.com","avatar":"https://gravatar.com/avatar/3767134496b3344f758bafc6cf8b5be08e212193fcaaff9dc819b732b5a0c476?d=mp&s=160"},"body":"I am writing a script for git-gui's \"Tools\" menu to diff a file.\nI want to checkout an origin file in a tmp directory and use the diff tool.\nNow it is ok to those unstage file,but to those staged file,\nI found that I do not know how to checkout the orgin(unstage) version.\n\nIn detail,I change current directory to a tmp directory,\nand use for example \n'git --work-tree=. --git-dir=\"/media/linux/t/kernel/.git\" checkout README'\n to checkout origin version.\n\nDoes anyone can help with this? \nI look the git help and can not find way till now.\n\nThanks!\n"},{"id":"161391","messageId":"4D5CDBAD.4050700@drmicha.warpmail.net","threadId":"26530","inReplyTo":"loom.20110217T074533-358@post.gmane.org","subject":"Re: How to git checkout a orgin(unstage) version file in another directoy?","fromName":"Michael J Gruber","fromEmail":"git@drmicha.warpmail.net","sentAt":"2011-02-17T08:26:21Z","receivedAt":"2011-02-17T08:26:21Z","isPatch":false,"sender":{"key":"git@grubix.eu","avatar":"https://avatars.githubusercontent.com/u/233215?v=4"},"body":"Chunlin Zhang venit, vidit, dixit 17.02.2011 08:00:\n> I am writing a script for git-gui's \"Tools\" menu to diff a file.\n> I want to checkout an origin file in a tmp directory and use the diff tool.\n> Now it is ok to those unstage file,but to those staged file,\n> I found that I do not know how to checkout the orgin(unstage) version.\n> \n> In detail,I change current directory to a tmp directory,\n> and use for example \n> 'git --work-tree=. --git-dir=\"/media/linux/t/kernel/.git\" checkout README'\n>  to checkout origin version.\n> \n> Does anyone can help with this? \n> I look the git help and can not find way till now.\n> \n> Thanks!\n> \n\nI'm not sure what you mean by \"origin\" version, but if you mean the\nversion from the current revision (before making and staging changes),\nyou would check out from HEAD instead of from the index:\n\ngit --work-tree=. --git-dir=\"/media/linux/t/kernel/.git\" checkout HEAD\n-- README\n\nMichael\n"},{"id":"161397","messageId":"loom.20110217T110216-810@post.gmane.org","threadId":"26530","inReplyTo":"4D5CDBAD.4050700@drmicha.warpmail.net","subject":"Re: How to git checkout a orgin(unstage) version file in another directoy?","fromName":"Chunlin Zhang","fromEmail":"zhangchunlin@gmail.com","sentAt":"2011-02-17T10:03:04Z","receivedAt":"2011-02-17T10:03:04Z","isPatch":false,"sender":{"key":"zhangchunlin@gmail.com","avatar":"https://gravatar.com/avatar/3767134496b3344f758bafc6cf8b5be08e212193fcaaff9dc819b732b5a0c476?d=mp&s=160"},"body":"Michael J Gruber <git <at> drmicha.warpmail.net> writes:\n\n> \n> I'm not sure what you mean by \"origin\" version, but if you mean the\n> version from the current revision (before making and staging changes),\n> you would check out from HEAD instead of from the index:\nYes,I mean HEAD version.\n> \n> git --work-tree=. --git-dir=\"/media/linux/t/kernel/.git\" checkout HEAD\nIt works! Thank you very much!\n"},{"id":"161398","messageId":"loom.20110217T110820-459@post.gmane.org","threadId":"26530","inReplyTo":"4D5CDBAD.4050700@drmicha.warpmail.net","subject":"Re: How to git checkout a orgin(unstage) version file in another directoy?","fromName":"Chunlin Zhang","fromEmail":"zhangchunlin@gmail.com","sentAt":"2011-02-17T10:17:45Z","receivedAt":"2011-02-17T10:17:45Z","isPatch":false,"sender":{"key":"zhangchunlin@gmail.com","avatar":"https://gravatar.com/avatar/3767134496b3344f758bafc6cf8b5be08e212193fcaaff9dc819b732b5a0c476?d=mp&s=160"},"body":"Michael J Gruber <git <at> drmicha.warpmail.net> writes:\n\n> git --work-tree=. --git-dir=\"/media/linux/t/kernel/.git\" checkout HEAD\nBut after I test,I found that after run this command,the file I do \ncheckout action become unstaged.\nIt is weard,because I have set the \"--work-tree\" to another directory.\nmy command line for example:\ngit --work-tree=. --git-dir=\"/media/linux/t/kernel/.git\" checkout \nHEAD -- Android.mk\n\nYou can test with a git repository.I have no idea how to work around now.\n"},{"id":"161400","messageId":"20110217103431.GA8308@elie","threadId":"26530","inReplyTo":"loom.20110217T074533-358@post.gmane.org","subject":"Re: How to git checkout a orgin(unstage) version file in another directoy?","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2011-02-17T10:34:31Z","receivedAt":"2011-02-17T10:34:31Z","isPatch":false,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Chunlin Zhang wrote:\n\n> I am writing a script for git-gui's \"Tools\" menu to diff a file.\n> I want to checkout an origin file in a tmp directory and use the diff tool.\n\nBecause you are writing a script, I'd suggest using one of the\n\"low-level commands (plumbing)\" listed in git(1).  Because you are\nretrieving a file, it would be one of the \"interrogation commands\".\nAnd because it is a single file, I suppose this should be git\ncat-file, git unpack-file, or git archive.\n\nFor example,\n\n\tgit cat-file blob HEAD:README\n\nwill print the contents of README in the HEAD commit.\n\nBecause I am curious: what exactly would your script be used to do?\nCan the git diff-tree or git diff-files command help?\n"},{"id":"161407","messageId":"loom.20110217T130405-970@post.gmane.org","threadId":"26530","inReplyTo":"20110217103431.GA8308@elie","subject":"Re: How to git checkout a orgin(unstage) version file in another directoy?","fromName":"Chunlin Zhang","fromEmail":"zhangchunlin@gmail.com","sentAt":"2011-02-17T12:06:33Z","receivedAt":"2011-02-17T12:06:33Z","isPatch":false,"sender":{"key":"zhangchunlin@gmail.com","avatar":"https://gravatar.com/avatar/3767134496b3344f758bafc6cf8b5be08e212193fcaaff9dc819b732b5a0c476?d=mp&s=160"},"body":"Jonathan Nieder <jrnieder <at> gmail.com> writes:\n\n> \n> Chunlin Zhang wrote:\n> Because you are writing a script, I'd suggest using one of the\n> \"low-level commands (plumbing)\" listed in git(1).  Because you are\n> retrieving a file, it would be one of the \"interrogation commands\".\n> And because it is a single file, I suppose this should be git\n> cat-file, git unpack-file, or git archive.\n> \n> For example,\n> \n> \tgit cat-file blob HEAD:README\nWow,this solved my problem perfectly.\nuse this command for example:\ngit --work-tree=. --git-dir=\"/media/linux/t/kernel/.git\" cat-file blob \nHEAD:Android.mk>Android.mk\n\nThanks !\n\n> \n> will print the contents of README in the HEAD commit.\n> \n> Because I am curious: what exactly would your script be used to do?\n> Can the git diff-tree or git diff-files command help?\n> \n"},{"id":"161413","messageId":"4D5D1603.6040208@drmicha.warpmail.net","threadId":"26530","inReplyTo":"loom.20110217T110820-459@post.gmane.org","subject":"Re: How to git checkout a orgin(unstage) version file in another directoy?","fromName":"Michael J Gruber","fromEmail":"git@drmicha.warpmail.net","sentAt":"2011-02-17T12:35:15Z","receivedAt":"2011-02-17T12:35:15Z","isPatch":false,"sender":{"key":"git@grubix.eu","avatar":"https://avatars.githubusercontent.com/u/233215?v=4"},"body":"Chunlin Zhang venit, vidit, dixit 17.02.2011 11:17:\n> Michael J Gruber <git <at> drmicha.warpmail.net> writes:\n> \n>> git --work-tree=. --git-dir=\"/media/linux/t/kernel/.git\" checkout HEAD\n> But after I test,I found that after run this command,the file I do \n> checkout action become unstaged.\n> It is weard,because I have set the \"--work-tree\" to another directory.\n> my command line for example:\n> git --work-tree=. --git-dir=\"/media/linux/t/kernel/.git\" checkout \n> HEAD -- Android.mk\n> \n> You can test with a git repository.I have no idea how to work around now.\n> \n\nSo, you don't really want to \"checkout\" the file. You only want its\ncontents without updating the index. (My brain is apparently too\ngit-rotted already to even think of the possibility that you didn't mean\n\"our checkout\" by \"checkout\").\n\nJonathan gave you the perfect solution for what you want.\n\nMichael\n"},{"id":"161421","messageId":"loom.20110217T142701-926@post.gmane.org","threadId":"26530","inReplyTo":"4D5D1603.6040208@drmicha.warpmail.net","subject":"Re: How to git checkout a orgin(unstage) version file in another directoy?","fromName":"Chunlin Zhang","fromEmail":"zhangchunlin@gmail.com","sentAt":"2011-02-17T13:30:31Z","receivedAt":"2011-02-17T13:30:31Z","isPatch":false,"sender":{"key":"zhangchunlin@gmail.com","avatar":"https://gravatar.com/avatar/3767134496b3344f758bafc6cf8b5be08e212193fcaaff9dc819b732b5a0c476?d=mp&s=160"},"body":"Michael J Gruber <git <at> drmicha.warpmail.net> writes:\n> So, you don't really want to \"checkout\" the file. You only want its\n> contents without updating the index. (My brain is apparently too\n> git-rotted already to even think of the possibility that you didn't mean\n> \"our checkout\" by \"checkout\").\nYes,I am a git newbie,a little bit misunderstanding about the git-checkout.\n> \n> Jonathan gave you the perfect solution for what you want.\nAnyway,your answer make me more familiar about git cli usage.\n> \n> Michael\n> \n"},{"id":"161430","messageId":"m2r5b6y40v.fsf@igel.home","threadId":"26530","inReplyTo":"loom.20110217T130405-970@post.gmane.org","subject":"Re: How to git checkout a orgin(unstage) version file in another directoy?","fromName":"Andreas Schwab","fromEmail":"schwab@linux-m68k.org","sentAt":"2011-02-17T17:17:20Z","receivedAt":"2011-02-17T17:17:20Z","isPatch":false,"sender":{"key":"schwab@linux-m68k.org","avatar":"https://avatars.githubusercontent.com/u/2175493?v=4"},"body":"Chunlin Zhang <zhangchunlin@gmail.com> writes:\n\n> use this command for example:\n> git --work-tree=. --git-dir=\"/media/linux/t/kernel/.git\" cat-file blob \n> HEAD:Android.mk>Android.mk\n\nYou won't need --work-tree any more, since cat-file only looks at the\nobject database.\n\nAndreas.\n\n-- \nAndreas Schwab, schwab@linux-m68k.org\nGPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5\n\"And now for something completely different.\"\n"},{"id":"161435","messageId":"7vpqqqcxzf.fsf@alter.siamese.dyndns.org","threadId":"26530","inReplyTo":"4D5CDBAD.4050700@drmicha.warpmail.net","subject":"Re: How to git checkout a orgin(unstage) version file in another directoy?","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2011-02-17T18:33:24Z","receivedAt":"2011-02-17T18:33:24Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Michael J Gruber <git@drmicha.warpmail.net> writes:\n\n> I'm not sure what you mean by \"origin\" version, but if you mean the\n> version from the current revision (before making and staging changes),\n> you would check out from HEAD instead of from the index:\n>\n> git --work-tree=. --git-dir=\"/media/linux/t/kernel/.git\" checkout HEAD\n> -- README\n\nWouldn't that still affect the index in /media/linux/t/kernel/.git/index,\nmaking /media/linux/t/kernel/README and the index entry out-of-sync?\n"},{"id":"161517","messageId":"4D5E22BE.301@drmicha.warpmail.net","threadId":"26530","inReplyTo":"7vpqqqcxzf.fsf@alter.siamese.dyndns.org","subject":"Re: How to git checkout a orgin(unstage) version file in another directoy?","fromName":"Michael J Gruber","fromEmail":"git@drmicha.warpmail.net","sentAt":"2011-02-18T07:41:50Z","receivedAt":"2011-02-18T07:41:50Z","isPatch":false,"sender":{"key":"git@grubix.eu","avatar":"https://avatars.githubusercontent.com/u/233215?v=4"},"body":"Junio C Hamano venit, vidit, dixit 17.02.2011 19:33:\n> Michael J Gruber <git@drmicha.warpmail.net> writes:\n> \n>> I'm not sure what you mean by \"origin\" version, but if you mean the\n>> version from the current revision (before making and staging changes),\n>> you would check out from HEAD instead of from the index:\n>>\n>> git --work-tree=. --git-dir=\"/media/linux/t/kernel/.git\" checkout HEAD\n>> -- README\n> \n> Wouldn't that still affect the index in /media/linux/t/kernel/.git/index,\n> making /media/linux/t/kernel/README and the index entry out-of-sync?\n\nYes. I guess you overlooked the two posts where Chunlin and I realised\nthat I took his request for \"checkout\" too giterally.\n\nMichael\n"}]}