Restoring files from old commits
What is the recommended way to restore individual files (or directories) in the working tree to the content they had in a given commit?
That is to say, now that Cogito is deprecated, what should I use instead of cg-restore?
Cheers,
-- Nikodemus
also sprach Nikodemus Siivola <[email protected]> [2007.07.14.1409 +0200]:
Quoted 3 lines
What is the recommended way to restore individual files (or directories) in the working tree to the content they had in a given commit?
As per my comment on IRC, I think
git checkout <tree-ish> <path>
is the way.
Signature · 8 lines
martin; (greetings from the heart of the sun.) \____ echo mailto: !#^."<*>"|tr "<*> mailto:" net@madduck spamtraps: [email protected] "the difference between genius and stupidity is that genius has it's limits." -- albert einstein
martin f krafft, Sat, Jul 14, 2007 14:37:54 +0200:
Quoted 10 lines
also sprach Nikodemus Siivola <[email protected]> [2007.07.14.1409 +0200]:
Quoted 3 lines
What is the recommended way to restore individual files (or directories) in the working tree to the content they had in a given commit?
As per my comment on IRC, I think
git checkout <tree-ish> <path>
is the way.
It does not work for directories, though. On can use
$ git ls-tree -r -z <tree-ish> -- <path> | git update-index -z --index-info
$ git ls-tree -r --name-only -z <tree-ish> -- <path> | git checkout-index -f -z --stdinfor a more generic way to do this.
P.S. Martin, would you please stop removing people from address lists and stop using that Mail-Followup-To? People miss their mails when they are not addressed to them anymore and you doing exactly that.
Quoted 6 lines · Alex Riesen
martin f krafft, Sat, Jul 14, 2007 14:37:54 +0200:
Quoted 5 lines
also sprach Nikodemus Siivola <[email protected]> [2007.07.14.1409 +0200]:
Quoted 3 lines
What is the recommended way to restore individual files (or directories) in the working tree to the content they had in a given commit?
Quoted 7 lines
Quoted 5 lines
As per my comment on IRC, I think
git checkout <tree-ish> <path>
is the way.
It does not work for directories, though.
Are you sure about that? I just did this in my git.git workspace:
$ mv Documentation Documentation-
$ git checkout HEAD Documentation/
$ diff -r Documentation- DocumentationJunio C Hamano, Sat, Jul 14, 2007 20:50:49 +0200:
Quoted 10 lines
Quoted 2 lines · Alex Riesen
It does not work for directories, though.
Are you sure about that? I just did this in my git.git workspace:
$ mv Documentation Documentation- $ git checkout HEAD Documentation/ $ diff -r Documentation- Documentation
Missed it. Happy now :)
Tangentially related to my previous question:
Every once and a while I want to examine an older version of a file in an editor.
(The typical case is first looking for the source of a change with git-blame, and then wanting to look at the original code and the diff side by side.)
My current (suboptimal, I hope!) way of doing getting the file is git-cat-file: first look at the commit, then look at the tree, ... till I find the SHA1 for the file I want.
git-checkout <sha1-of-commit> <path>, but that leaves the old version in both the index and the tree, which feels icky especially if I'm giving this treatment to multiple files at the same time.
So what I'd like is something like
git cat-path <commit> <path-in-the-tree-referenced-by-that-commit>
Does this exist, or is this scripting time?
Cheers,
-- Nikodemus
Hello Nikodemus,
Quoted 3 lines · Nikodemus Siivola
So what I'd like is something like
git cat-path <commit> <path-in-the-tree-referenced-by-that-commit>
Try:
git show <commit>:<path-in-the-tree-referenced-by-that-commit>
Best regards
Uwe
Signature · 3 lines
Uwe Kleine-König http://www.google.com/search?q=half+a+cup+in+teaspoons
Nikodemus Siivola пишет:
Quoted 5 lines
So what I'd like is something like
git cat-path <commit> <path-in-the-tree-referenced-by-that-commit>
Does this exist, or is this scripting time?
Have you tried
git show <commit>:<path>
?