git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* How to git checkout a orgin(unstage) version file in another directoy?
@ 2011-02-17  7:00 Chunlin Zhang
  2011-02-17  8:26 ` Michael J Gruber
  2011-02-17 10:34 ` Jonathan Nieder
  0 siblings, 2 replies; 11+ messages in thread
From: Chunlin Zhang @ 2011-02-17  7:00 UTC (permalink / raw)
  To: git

I am writing a script for git-gui's "Tools" menu to diff a file.
I want to checkout an origin file in a tmp directory and use the diff tool.
Now it is ok to those unstage file,but to those staged file,
I found that I do not know how to checkout the orgin(unstage) version.

In detail,I change current directory to a tmp directory,
and use for example 
'git --work-tree=. --git-dir="/media/linux/t/kernel/.git" checkout README'
 to checkout origin version.

Does anyone can help with this? 
I look the git help and can not find way till now.

Thanks!

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: How to git checkout a orgin(unstage) version file in another directoy?
  2011-02-17  7:00 How to git checkout a orgin(unstage) version file in another directoy? Chunlin Zhang
@ 2011-02-17  8:26 ` Michael J Gruber
  2011-02-17 10:03   ` Chunlin Zhang
                     ` (2 more replies)
  2011-02-17 10:34 ` Jonathan Nieder
  1 sibling, 3 replies; 11+ messages in thread
From: Michael J Gruber @ 2011-02-17  8:26 UTC (permalink / raw)
  To: Chunlin Zhang; +Cc: git

Chunlin Zhang venit, vidit, dixit 17.02.2011 08:00:
> I am writing a script for git-gui's "Tools" menu to diff a file.
> I want to checkout an origin file in a tmp directory and use the diff tool.
> Now it is ok to those unstage file,but to those staged file,
> I found that I do not know how to checkout the orgin(unstage) version.
> 
> In detail,I change current directory to a tmp directory,
> and use for example 
> 'git --work-tree=. --git-dir="/media/linux/t/kernel/.git" checkout README'
>  to checkout origin version.
> 
> Does anyone can help with this? 
> I look the git help and can not find way till now.
> 
> Thanks!
> 

I'm not sure what you mean by "origin" version, but if you mean the
version from the current revision (before making and staging changes),
you would check out from HEAD instead of from the index:

git --work-tree=. --git-dir="/media/linux/t/kernel/.git" checkout HEAD
-- README

Michael

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: How to git checkout a orgin(unstage) version file in another directoy?
  2011-02-17  8:26 ` Michael J Gruber
@ 2011-02-17 10:03   ` Chunlin Zhang
  2011-02-17 10:17   ` Chunlin Zhang
  2011-02-17 18:33   ` Junio C Hamano
  2 siblings, 0 replies; 11+ messages in thread
From: Chunlin Zhang @ 2011-02-17 10:03 UTC (permalink / raw)
  To: git

Michael J Gruber <git <at> drmicha.warpmail.net> writes:

> 
> I'm not sure what you mean by "origin" version, but if you mean the
> version from the current revision (before making and staging changes),
> you would check out from HEAD instead of from the index:
Yes,I mean HEAD version.
> 
> git --work-tree=. --git-dir="/media/linux/t/kernel/.git" checkout HEAD
It works! Thank you very much!

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: How to git checkout a orgin(unstage) version file in another directoy?
  2011-02-17  8:26 ` Michael J Gruber
  2011-02-17 10:03   ` Chunlin Zhang
@ 2011-02-17 10:17   ` Chunlin Zhang
  2011-02-17 12:35     ` Michael J Gruber
  2011-02-17 18:33   ` Junio C Hamano
  2 siblings, 1 reply; 11+ messages in thread
From: Chunlin Zhang @ 2011-02-17 10:17 UTC (permalink / raw)
  To: git

Michael J Gruber <git <at> drmicha.warpmail.net> writes:

> git --work-tree=. --git-dir="/media/linux/t/kernel/.git" checkout HEAD
But after I test,I found that after run this command,the file I do 
checkout action become unstaged.
It is weard,because I have set the "--work-tree" to another directory.
my command line for example:
git --work-tree=. --git-dir="/media/linux/t/kernel/.git" checkout 
HEAD -- Android.mk

You can test with a git repository.I have no idea how to work around now.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: How to git checkout a orgin(unstage) version file in another directoy?
  2011-02-17  7:00 How to git checkout a orgin(unstage) version file in another directoy? Chunlin Zhang
  2011-02-17  8:26 ` Michael J Gruber
@ 2011-02-17 10:34 ` Jonathan Nieder
  2011-02-17 12:06   ` Chunlin Zhang
  1 sibling, 1 reply; 11+ messages in thread
From: Jonathan Nieder @ 2011-02-17 10:34 UTC (permalink / raw)
  To: Chunlin Zhang; +Cc: git, Michael J Gruber

Chunlin Zhang wrote:

> I am writing a script for git-gui's "Tools" menu to diff a file.
> I want to checkout an origin file in a tmp directory and use the diff tool.

Because you are writing a script, I'd suggest using one of the
"low-level commands (plumbing)" listed in git(1).  Because you are
retrieving a file, it would be one of the "interrogation commands".
And because it is a single file, I suppose this should be git
cat-file, git unpack-file, or git archive.

For example,

	git cat-file blob HEAD:README

will print the contents of README in the HEAD commit.

Because I am curious: what exactly would your script be used to do?
Can the git diff-tree or git diff-files command help?

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: How to git checkout a orgin(unstage) version file in another directoy?
  2011-02-17 10:34 ` Jonathan Nieder
@ 2011-02-17 12:06   ` Chunlin Zhang
  2011-02-17 17:17     ` Andreas Schwab
  0 siblings, 1 reply; 11+ messages in thread
From: Chunlin Zhang @ 2011-02-17 12:06 UTC (permalink / raw)
  To: git

Jonathan Nieder <jrnieder <at> gmail.com> writes:

> 
> Chunlin Zhang wrote:
> Because you are writing a script, I'd suggest using one of the
> "low-level commands (plumbing)" listed in git(1).  Because you are
> retrieving a file, it would be one of the "interrogation commands".
> And because it is a single file, I suppose this should be git
> cat-file, git unpack-file, or git archive.
> 
> For example,
> 
> 	git cat-file blob HEAD:README
Wow,this solved my problem perfectly.
use this command for example:
git --work-tree=. --git-dir="/media/linux/t/kernel/.git" cat-file blob 
HEAD:Android.mk>Android.mk

Thanks !

> 
> will print the contents of README in the HEAD commit.
> 
> Because I am curious: what exactly would your script be used to do?
> Can the git diff-tree or git diff-files command help?
> 

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: How to git checkout a orgin(unstage) version file in another directoy?
  2011-02-17 10:17   ` Chunlin Zhang
@ 2011-02-17 12:35     ` Michael J Gruber
  2011-02-17 13:30       ` Chunlin Zhang
  0 siblings, 1 reply; 11+ messages in thread
From: Michael J Gruber @ 2011-02-17 12:35 UTC (permalink / raw)
  To: Chunlin Zhang; +Cc: git

Chunlin Zhang venit, vidit, dixit 17.02.2011 11:17:
> Michael J Gruber <git <at> drmicha.warpmail.net> writes:
> 
>> git --work-tree=. --git-dir="/media/linux/t/kernel/.git" checkout HEAD
> But after I test,I found that after run this command,the file I do 
> checkout action become unstaged.
> It is weard,because I have set the "--work-tree" to another directory.
> my command line for example:
> git --work-tree=. --git-dir="/media/linux/t/kernel/.git" checkout 
> HEAD -- Android.mk
> 
> You can test with a git repository.I have no idea how to work around now.
> 

So, you don't really want to "checkout" the file. You only want its
contents without updating the index. (My brain is apparently too
git-rotted already to even think of the possibility that you didn't mean
"our checkout" by "checkout").

Jonathan gave you the perfect solution for what you want.

Michael

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: How to git checkout a orgin(unstage) version file in another directoy?
  2011-02-17 12:35     ` Michael J Gruber
@ 2011-02-17 13:30       ` Chunlin Zhang
  0 siblings, 0 replies; 11+ messages in thread
From: Chunlin Zhang @ 2011-02-17 13:30 UTC (permalink / raw)
  To: git

Michael J Gruber <git <at> drmicha.warpmail.net> writes:
> So, you don't really want to "checkout" the file. You only want its
> contents without updating the index. (My brain is apparently too
> git-rotted already to even think of the possibility that you didn't mean
> "our checkout" by "checkout").
Yes,I am a git newbie,a little bit misunderstanding about the git-checkout.
> 
> Jonathan gave you the perfect solution for what you want.
Anyway,your answer make me more familiar about git cli usage.
> 
> Michael
> 

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: How to git checkout a orgin(unstage) version file in another directoy?
  2011-02-17 12:06   ` Chunlin Zhang
@ 2011-02-17 17:17     ` Andreas Schwab
  0 siblings, 0 replies; 11+ messages in thread
From: Andreas Schwab @ 2011-02-17 17:17 UTC (permalink / raw)
  To: Chunlin Zhang; +Cc: git

Chunlin Zhang <zhangchunlin@gmail.com> writes:

> use this command for example:
> git --work-tree=. --git-dir="/media/linux/t/kernel/.git" cat-file blob 
> HEAD:Android.mk>Android.mk

You won't need --work-tree any more, since cat-file only looks at the
object database.

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: How to git checkout a orgin(unstage) version file in another directoy?
  2011-02-17  8:26 ` Michael J Gruber
  2011-02-17 10:03   ` Chunlin Zhang
  2011-02-17 10:17   ` Chunlin Zhang
@ 2011-02-17 18:33   ` Junio C Hamano
  2011-02-18  7:41     ` Michael J Gruber
  2 siblings, 1 reply; 11+ messages in thread
From: Junio C Hamano @ 2011-02-17 18:33 UTC (permalink / raw)
  To: Michael J Gruber; +Cc: Chunlin Zhang, git

Michael J Gruber <git@drmicha.warpmail.net> writes:

> I'm not sure what you mean by "origin" version, but if you mean the
> version from the current revision (before making and staging changes),
> you would check out from HEAD instead of from the index:
>
> git --work-tree=. --git-dir="/media/linux/t/kernel/.git" checkout HEAD
> -- README

Wouldn't that still affect the index in /media/linux/t/kernel/.git/index,
making /media/linux/t/kernel/README and the index entry out-of-sync?

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: How to git checkout a orgin(unstage) version file in another directoy?
  2011-02-17 18:33   ` Junio C Hamano
@ 2011-02-18  7:41     ` Michael J Gruber
  0 siblings, 0 replies; 11+ messages in thread
From: Michael J Gruber @ 2011-02-18  7:41 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Chunlin Zhang, git

Junio C Hamano venit, vidit, dixit 17.02.2011 19:33:
> Michael J Gruber <git@drmicha.warpmail.net> writes:
> 
>> I'm not sure what you mean by "origin" version, but if you mean the
>> version from the current revision (before making and staging changes),
>> you would check out from HEAD instead of from the index:
>>
>> git --work-tree=. --git-dir="/media/linux/t/kernel/.git" checkout HEAD
>> -- README
> 
> Wouldn't that still affect the index in /media/linux/t/kernel/.git/index,
> making /media/linux/t/kernel/README and the index entry out-of-sync?

Yes. I guess you overlooked the two posts where Chunlin and I realised
that I took his request for "checkout" too giterally.

Michael

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2011-02-18  7:45 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-02-17  7:00 How to git checkout a orgin(unstage) version file in another directoy? Chunlin Zhang
2011-02-17  8:26 ` Michael J Gruber
2011-02-17 10:03   ` Chunlin Zhang
2011-02-17 10:17   ` Chunlin Zhang
2011-02-17 12:35     ` Michael J Gruber
2011-02-17 13:30       ` Chunlin Zhang
2011-02-17 18:33   ` Junio C Hamano
2011-02-18  7:41     ` Michael J Gruber
2011-02-17 10:34 ` Jonathan Nieder
2011-02-17 12:06   ` Chunlin Zhang
2011-02-17 17:17     ` Andreas Schwab

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).