4

I have a working tree on my local machine, and a remote repository as well. Let's say I want to quickly build an earlier version of my project at a known tag without disturbing the current state of the working version. My inclination is to checkout a separate tree, which seems to go like in this question:

Download a specific tag with Git

With a clone from the remote repository followed by a checkout in there. But the clone does a lot of work and pulls down all the revision state. Is there any lightweight way of saying "grab me the current state of the world at this commit/tag and spray it into this directory?" (Further revision control not necessary-- it's "read only" as far as Git should be concerned.)

Maybe not-- just checking.

Thanks.

Zoe
  • 27,060
  • 21
  • 118
  • 148
Ben Zotto
  • 70,108
  • 23
  • 141
  • 204

3 Answers3

5

If it's all local, you can do this:

mkdir /path/to/test-tree
cd /path/to/repo
git read-tree <tag>
git checkout-index -a --prefix=/path/to/test-tree/  # don't forget the last slash

# read-tree copies content into the index
# to restore it:
git read-tree HEAD

That's assuming you don't care about the other tree having any git information at all. If you want it to, you could use the git-new-workdir script, which basically creates a clone, except populating the .git directory with symlinks back to the original repo, so that it takes no extra disk space. It's a nice approach - no extra disk space, and you can use one repo for development, one for testing, etc.

Cascabel
  • 479,068
  • 72
  • 370
  • 318
1

Try

git checkout -b new_branch [previous_tag]
Chetan
  • 46,743
  • 31
  • 106
  • 145
  • Not sure I want to create a "branch". After I'm done with my read-only tree, I'll usually just `rm -rf` it and forget about it. Creating a branch creates state inside Git, right? – Ben Zotto Oct 21 '10 at 22:58
  • @quixoto: Well, you can just do `git branch -D new_branch`, and the branch is gone as if it never existed. – Chetan Oct 21 '10 at 23:12
  • Sounds like y'all are talking across each other. Chetan, the OP wants a separate tree, without disturbing the repo's current tree - so no checking out within there. – Cascabel Oct 21 '10 at 23:27
  • @Jefromi: Ah, I see. Sorry about that! – Chetan Oct 21 '10 at 23:44
0

Sounds like you're looking for git-export: Do a "git export" (like "svn export")?

Community
  • 1
  • 1
Brad Mace
  • 27,194
  • 17
  • 102
  • 148