threads / discuss / 3745

Cherry-pick particular object

Subject: Cherry-pick particular object

## tl;dr

9 messages between Mar 28, 2006 and Mar 28, 2006.

replies: 8people: 6as markdown or json

Sébastien Pierre· Mar 28, 2006, 16:31 UTC · lore
Hi all,
This is a newbie question.
I recently wanted to "cherry" pick a particular file from my git-managed project history. Using gitk, I identified which was the revision I wanted (95ba0c74e03874e8c1721b91f92f161e9061621f), and then using git ls-tree, I managed to get the id of the file I wanted (78132af26431e649a0f85f22dc27e5787d80700f).
Now, what I simply wanted was to do something like:
"get the file corresponding to 78132af26431e649a0f85f22dc27e5787d80700f and save it as myfile.txt"
How would one properly do that with core git ?
 -- Sébastien
sean· Mar 28, 2006, 21:34 UTC · re: Sébastien Pierre · lore

Re: Cherry-pick particular object

On Tue, 28 Mar 2006 11:31:07 -0500 Sébastien Pierre <sebastien@xprima.com> wrote:

Show 16 quoted lines
> Hi all,
> 
> This is a newbie question.
> 
> I recently wanted to "cherry" pick a particular file from my 
> git-managed project history. Using gitk, I identified which was 
> the revision I wanted (95ba0c74e03874e8c1721b91f92f161e9061621f), 
> and then using git ls-tree, I managed to get the id of the file I 
> wanted (78132af26431e649a0f85f22dc27e5787d80700f).
> 
> Now, what I simply wanted was to do something like:
> 
> "get the file corresponding to 78132af26431e649a0f85f22dc27e5787d80700f 
>  and save it as myfile.txt"
> 
> How would one properly do that with core git ?
If you used:
$ git cat-file -t 78132af2643

It would tell you that this object is of type "blob". To see the contents of blobs you can do something like:

$ git cat-file blob 78132af2643
Sean
Sébastien Pierre· Mar 28, 2006, 17:23 UTC · re: sean · lore

Re: Cherry-pick particular object

On Tue, 28 Mar 2006 16:34:22 -0500 sean <seanlkml@sympatico.ca> wrote:

Show 8 quoted lines
> If you used:
> 
> $ git cat-file -t 78132af2643
> 
> It would tell you that this object is of type "blob".
> To see the contents of blobs you can do something like:
> 
> $ git cat-file blob 78132af2643
Thanks. That was exactly what I was looking for :)
 -- Sébastien
Linus Torvalds· Mar 28, 2006, 22:44 UTC · re: sean · lore

Re: Cherry-pick particular object

On Tue, 28 Mar 2006, sean wrote:
> 
> $ git cat-file -t 78132af2643

Side note: when using git-ls-tree, the "blob"ness information is already in the tree output itself and you shouldn't even need to check the type with "-t". So what is perhaps somewhat more interesting is actually the mode of the file, since that determines whether the blob should be interpreted as regular file content or as a symlink.

Ie you can have a tree like this:
	100644 blob f2ba8f84ab5c1bce84a7b441cb1959cfc7093b7f    abc
	120000 blob f2ba8f84ab5c1bce84a7b441cb1959cfc7093b7f    file

where the first one is a regular file called "abc" (which contains the string "abc"), and the second is the _symlink_ that points to "abc".

They share the exact same blob, and what distinguishes them is the filemode info from git-read-tree.

Of course, the symlink case isn't very common and likely not very interesting in this case, but the fact that "git ls-files" is set up so that you can just cut-and-paste the "blob <sha1-of-blob" part and feed it to git-cat-file was definitely not just coincidence.

(A number of the early stuff was set up so that I could do things by hand by just doing cut-and-paste of the output of the previous command. Git has come a long way in the last 12 months ;)

		Linus
Petr Baudis· Mar 28, 2006, 22:54 UTC · re: Linus Torvalds · lore

Re: Cherry-pick particular object

Dear diary, on Wed, Mar 29, 2006 at 12:44:02AM CEST, I got a letter where Linus Torvalds <torvalds@osdl.org> said that...

Show 10 quoted lines
> Ie you can have a tree like this:
> 
> 	100644 blob f2ba8f84ab5c1bce84a7b441cb1959cfc7093b7f    abc
> 	120000 blob f2ba8f84ab5c1bce84a7b441cb1959cfc7093b7f    file
> 
> where the first one is a regular file called "abc" (which contains the 
> string "abc"), and the second is the _symlink_ that points to "abc".
> 
> They share the exact same blob, and what distinguishes them is the 
> filemode info from git-read-tree.

Huh? Didn't you rather want to say that "file" will point to a blob containing just the "abc" string (the symlink target)? ;-)

-- 
				Petr "Pasky" Baudis
Stuff: http://pasky.or.cz/
Right now I am having amnesia and deja-vu at the same time.  I think
I have forgotten this before.
Linus Torvalds· Mar 28, 2006, 23:24 UTC · re: Petr Baudis · lore

Re: Cherry-pick particular object

On Wed, 29 Mar 2006, Petr Baudis wrote:
Show 15 quoted lines
> Dear diary, on Wed, Mar 29, 2006 at 12:44:02AM CEST, I got a letter
> where Linus Torvalds <torvalds@osdl.org> said that...
> > Ie you can have a tree like this:
> > 
> > 	100644 blob f2ba8f84ab5c1bce84a7b441cb1959cfc7093b7f    abc
> > 	120000 blob f2ba8f84ab5c1bce84a7b441cb1959cfc7093b7f    file
> > 
> > where the first one is a regular file called "abc" (which contains the 
> > string "abc"), and the second is the _symlink_ that points to "abc".
> > 
> > They share the exact same blob, and what distinguishes them is the 
> > filemode info from git-read-tree.
> 
> Huh? Didn't you rather want to say that "file" will point to a blob
> containing just the "abc" string (the symlink target)? ;-)
Well no, maybe I should have called the first file something else.

Both "abc" and "file" from a git perspective have the same _contents_ (the blob containing the data 'abc').

But the filemode means that those contents have totally different meaning. For the pth "file", it means that it's a _symlink_ to "abc", while for the path "abc" it's a regular file that just has the _contents_ "abc".

So the end _result_ of this is that "file" points to a file called "abc" that also has the contents "abc", and "cat file abc" will result in "abcabc".

IOW, this is the result of doing
	echo -n abc > abc
	ln -s abc file
and importing the mess into git.
		Linus
Petr Baudis· Mar 28, 2006, 23:28 UTC · re: Linus Torvalds · lore

Re: Cherry-pick particular object

Dear diary, on Wed, Mar 29, 2006 at 01:24:13AM CEST, I got a letter where Linus Torvalds <torvalds@osdl.org> said that...

Show 22 quoted lines
> On Wed, 29 Mar 2006, Petr Baudis wrote:
> 
> > Dear diary, on Wed, Mar 29, 2006 at 12:44:02AM CEST, I got a letter
> > where Linus Torvalds <torvalds@osdl.org> said that...
> > > Ie you can have a tree like this:
> > > 
> > > 	100644 blob f2ba8f84ab5c1bce84a7b441cb1959cfc7093b7f    abc
> > > 	120000 blob f2ba8f84ab5c1bce84a7b441cb1959cfc7093b7f    file
> > > 
> > > where the first one is a regular file called "abc" (which contains the 
> > > string "abc"), and the second is the _symlink_ that points to "abc".
> > > 
> > > They share the exact same blob, and what distinguishes them is the 
> > > filemode info from git-read-tree.
> > 
> > Huh? Didn't you rather want to say that "file" will point to a blob
> > containing just the "abc" string (the symlink target)? ;-)
> 
> Well no, maybe I should have called the first file something else.
> 
> Both "abc" and "file" from a git perspective have the same _contents_ (the 
> blob containing the data 'abc'). 

Oh, I've totally missed the '(which contains the string "abc")' part, sorry. Apparently it's time to sleep for me. :/

-- 
				Petr "Pasky" Baudis
Stuff: http://pasky.or.cz/
Right now I am having amnesia and deja-vu at the same time.  I think
I have forgotten this before.
Shawn Pearce· Mar 28, 2006, 21:37 UTC · re: Sébastien Pierre · lore

Re: Cherry-pick particular object

S?bastien Pierre <sebastien@xprima.com> wrote:
Show 16 quoted lines
> Hi all,
> 
> This is a newbie question.
> 
> I recently wanted to "cherry" pick a particular file from my
> git-managed project history. Using gitk, I identified which was
> the revision I wanted (95ba0c74e03874e8c1721b91f92f161e9061621f),
> and then using git ls-tree, I managed to get the id of the file I
> wanted (78132af26431e649a0f85f22dc27e5787d80700f).
> 
> Now, what I simply wanted was to do something like:
> 
> "get the file corresponding to
> 78132af26431e649a0f85f22dc27e5787d80700f and save it as myfile.txt"
> 
> How would one properly do that with core git ?
git cat-file blob 78132af26431e649a0f85f22dc27e5787d80700f >myfile.txt
-- 
Shawn.
Tony Luck· Mar 28, 2006, 21:38 UTC · re: Sébastien Pierre · lore

Re: Cherry-pick particular object

> "get the file corresponding to 78132af26431e649a0f85f22dc27e5787d80700f and save it as myfile.txt"
>
> How would one properly do that with core git ?
$ git cat-file blob 78132af2643 > myfile.txt
-Tony

← back to recent threads