Cherry-pick particular object
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
Quoted 3 lines
"get the file corresponding to
78132af26431e649a0f85f22dc27e5787d80700fand save it as myfile.txt"How would one properly do that with core git ?
$ git cat-file blob 78132af2643 > myfile.txt
-Tony
Quoted 10 lines · S?bastien Pierre
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).
Quoted 6 lines
Now, what I simply wanted was to do something like:
"get the file corresponding to
78132af26431e649a0f85f22dc27e5787d80700fand save it as myfile.txt"How would one properly do that with core git ?
git cat-file blob 78132af26431e649a0f85f22dc27e5787d80700f >myfile.txt
Signature · 1 line
Shawn.
Quoted 10 lines · On Tue, 28 Mar 2006 11:31:07 -0500 Sébastien Pierre <[email protected]>…
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).
Quoted 6 lines
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
Quoted 8 lines · On Tue, 28 Mar 2006 16:34:22 -0500 sean <[email protected]> wrote:
If you used:
$ git cat-file -t 78132af2643It 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
Quoted 2 lines · sean
$ 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
Dear diary, on Wed, Mar 29, 2006 at 12:44:02AM CEST, I got a letter where Linus Torvalds <[email protected]> said that...
Quoted 10 lines
Ie you can have a tree like this:
100644 blob f2ba8f84ab5c1bce84a7b441cb1959cfc7093b7f abc 120000 blob f2ba8f84ab5c1bce84a7b441cb1959cfc7093b7f filewhere 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)? ;-)
Signature · 4 lines
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.
Quoted 7 lines · Petr Baudis
Dear diary, on Wed, Mar 29, 2006 at 12:44:02AM CEST, I got a letter where Linus Torvalds <[email protected]> said that...
Quoted 5 lines
Ie you can have a tree like this:
100644 blob f2ba8f84ab5c1bce84a7b441cb1959cfc7093b7f abc 120000 blob f2ba8f84ab5c1bce84a7b441cb1959cfc7093b7f file
Quoted 8 lines
Quoted 5 lines
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
Dear diary, on Wed, Mar 29, 2006 at 01:24:13AM CEST, I got a letter where Linus Torvalds <[email protected]> said that...
Quoted 15 lines · Petr Baudis
Quoted 14 lines
Dear diary, on Wed, Mar 29, 2006 at 12:44:02AM CEST, I got a letter where Linus Torvalds <[email protected]> said that...
Quoted 10 lines
Ie you can have a tree like this:
100644 blob f2ba8f84ab5c1bce84a7b441cb1959cfc7093b7f abc 120000 blob f2ba8f84ab5c1bce84a7b441cb1959cfc7093b7f filewhere 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.
Quoted 7 lines
Quoted 2 lines
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. :/
Signature · 4 lines
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.