Subject: Re: Simple UI question...

From: "Shawn O. Pearce" <[email-masked]>
Date: Sun, 7 Jan 2007 06:13:05 -0500

Chris Lee <[email-masked]> wrote:
> So I'm trying to figure out the best way to pull out a checkout of the
> entire tree as of a given revision ID. I have a whole bunch of
> revision IDs, and I'd like to know what the git equivalent of (say)
> the following is:
> 
> svn co -r280600 file:///path/to/svn/repo
> 
> For the sake of argument, let's say that r280600 imported as
> 07058310db903317faa300b93004a5a2e0fc2dcc into my git tree.
> 
> How do I get a pristine checkout in my working copy of the entire tree
> as the repository saw it at 07058310db903317faa300b93004a5a2e0fc2dcc?

One way is:

  git archive \
    --format=tar \
    07058310db903317faa300b93004a5a2e0fc2dcc \
    | (mkdir ../export; cd ../export; tar xf -)

Would give you a new directory tree which is not related to any
Git repository, but which contains the exact set of files in 070583.
But that's probably not what you meant.
 
> Eric Anholt suggested 'git checkout -b temporary-branch-name
> $sha1sum';

Yes, that is usually the way you do this.  Unlike the archive trick
above the result will be in your current working directory and
will be associated with the current Git repository.  Further you
can modify this and commit changes if you need to.

> davej suggested 'git-read-tree $sha1sum &&
> git-checkout-index -a -f'

That's just cruel.  Its only part of the underlying operations that
git checkout is performing, and its trashing your current branch
by making HEAD no longer match the index.  And its very low-level.
And it doesn't really do a 2-way merge to fully update the working
directory.  Not the best way for a user to perform this action.
Forget davej ever suggested this.

> but for some reason, neither of these
> commands seems to do exactly as I expect. davej's method seems to work
> for some revision IDs, but not for others, and the other method seems
> to work just about as well. (The problem I have seen is that, for some
> revisions, the only files I get in the working copy are the files that
> were changed in that commit; the rest of the files in the tree do not
> get checked out.)

The problem is davej's method doesn't take into account what the
current working directory actually has stored in it.  It does not
delete any files which should not appear in $sha1sum.  It also
overwrites more files than it needs to, as it overwrites everything
instead of just those files which actually differ between the
current working directory and $sha1sum.

Eric Anholt's version is the correct way to do it.  It is also very
fast as it only has to modify the files which actually differed.

If Eric's version isn't always working then I'd have to suggest
that you exmaine the output of `git status` for switching to
some temporary branch based on $sha1sum.  Perhaps you have local
modifications which are carrying over in your working directory?

-- 
Shawn.