# Cherry-pick particular object

9 messages from 2006-03-28 to 2006-03-28. Participants: Sébastien Pierre, sean, Shawn Pearce, Tony Luck, Linus Torvalds, Petr Baudis.
Thread: https://gitlist.dev/t/3745

## Sébastien Pierre, 2006-03-28 16:31

Subject: Cherry-pick particular object
Message-ID: <20060328113107.20ab4c21.sebastien@xprima.com>
URL: https://gitlist.dev/e/20060328113107.20ab4c21.sebastien%40xprima.com

```
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

```

## Sébastien Pierre, 2006-03-28 17:23

Subject: Re: Cherry-pick particular object
Message-ID: <20060328122301.f74ee9c4.sebastien@xprima.com>
URL: https://gitlist.dev/e/20060328122301.f74ee9c4.sebastien%40xprima.com
In-Reply-To: <BAYC1-PASMTP02B05019F52DE48793CB39AED30@CEZ.ICE>

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

> 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

```

## sean, 2006-03-28 21:34

Subject: Re: Cherry-pick particular object
Message-ID: <BAYC1-PASMTP02B05019F52DE48793CB39AED30@CEZ.ICE>
URL: https://gitlist.dev/e/BAYC1-PASMTP02B05019F52DE48793CB39AED30%40CEZ.ICE
In-Reply-To: <20060328113107.20ab4c21.sebastien@xprima.com>

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

> 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

```

## Shawn Pearce, 2006-03-28 21:37

Subject: Re: Cherry-pick particular object
Message-ID: <20060328213744.GD14457@spearce.org>
URL: https://gitlist.dev/e/20060328213744.GD14457%40spearce.org
In-Reply-To: <20060328113107.20ab4c21.sebastien@xprima.com>

```
S?bastien Pierre <sebastien@xprima.com> wrote:
> 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, 2006-03-28 21:38

Subject: Re: Cherry-pick particular object
Message-ID: <12c511ca0603281338q503638bfo66fa0a5da19942e2@mail.gmail.com>
URL: https://gitlist.dev/e/12c511ca0603281338q503638bfo66fa0a5da19942e2%40mail.gmail.com
In-Reply-To: <20060328113107.20ab4c21.sebastien@xprima.com>

```
> "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

```

## Linus Torvalds, 2006-03-28 22:44

Subject: Re: Cherry-pick particular object
Message-ID: <Pine.LNX.4.64.0603281435410.15714@g5.osdl.org>
URL: https://gitlist.dev/e/Pine.LNX.4.64.0603281435410.15714%40g5.osdl.org
In-Reply-To: <BAYC1-PASMTP02B05019F52DE48793CB39AED30@CEZ.ICE>

```


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, 2006-03-28 22:54

Subject: Re: Cherry-pick particular object
Message-ID: <20060328225429.GD27689@pasky.or.cz>
URL: https://gitlist.dev/e/20060328225429.GD27689%40pasky.or.cz
In-Reply-To: <Pine.LNX.4.64.0603281435410.15714@g5.osdl.org>

```
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)? ;-)

-- 
				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, 2006-03-28 23:24

Subject: Re: Cherry-pick particular object
Message-ID: <Pine.LNX.4.64.0603281512260.15714@g5.osdl.org>
URL: https://gitlist.dev/e/Pine.LNX.4.64.0603281512260.15714%40g5.osdl.org
In-Reply-To: <20060328225429.GD27689@pasky.or.cz>

```


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'). 

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, 2006-03-28 23:28

Subject: Re: Cherry-pick particular object
Message-ID: <20060328232851.GE27689@pasky.or.cz>
URL: https://gitlist.dev/e/20060328232851.GE27689%40pasky.or.cz
In-Reply-To: <Pine.LNX.4.64.0603281512260.15714@g5.osdl.org>

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

```
