git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Simple UI question...

From
Junio C Hamano <junkio@cox.net>
Date
Jan 7, 2007, 11:30 UTC
Message-ID
<7vodpb13bj.fsf@assigned-by-dhcp.cox.net>
In-Reply-To
<204011cb0701070302y54837c5bp967e2cddd3fb655d@mail.gmail.com>
"Chris Lee" <clee@kde.org> writes:
> Eric Anholt suggested 'git checkout -b temporary-branch-name
> $sha1sum'; davej suggested 'git-read-tree $sha1sum &&
> git-checkout-index -a -f' but for some reason, neither of these
> commands seems to do exactly as I expect.

These two do vastly different things (but the latter is flawed and does _not_ do what it is trying to do).

 - If this checkout is just to look-see, and if you are on a
   branch that is precious to you (say, you intend to keep
   importing from svn or other repository onto that branch),
   then you should use a temporary branch.  Eric's suggestion is
   this approach -- but "git checkout -b $branch $start" is
   about CREATING a new branch, so once you used the temporary
   branch name, you cannot expect the same command line with
   only different starting point to work.  In other words, I
   suspect you saw "it doesn't work" because you did this:
	$ git checkout -b foo $commit1
	$ git checkout -b foo $commit2
   and got an error message from the second one.
 - If you do not mind trashing the current branch, then "git
   reset --hard" is what you want, and what you said was Dave's
   suggestion is an incorrectly spelled version of old timer's
   way to do what "git reset --hard" does by hand.

Assuming that you do not want to trash your branch (and you usually don't), the correct sequence is first do:

	$ git checkout -b look-see

This creates a new branch "look-see" (the name does not matter as long as you do not have such a branch) from whatever branch you happen to be on and switch to it. After this, you will be on the new "look-see" branch. At which commit this branch starts does not matter.

Then, whichever commit you would want to check out and look at, you would do:

	$ git reset --hard $commit
 
This "trashes" look-see branch by moving to that commit -- it
trashes in the sense that it makes the "look-see" branch forget
about all commits that comes after you resetted to, but you do
not care because this branch is temporary branch you created.
Once you are done looking at this commit, you can repeatedly say
"git reset --hard" to move around to look at different commits.

Once you are done, you do not need to be on (nor need) look-see branch, so get rid of it.

	$ git checkout master
        $ git branch -D look-see
> ... (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.)

This is because the low-level commands in the above example to mimick "git reset --hard" does is flawed.

If you are curious,...
The way "git-reset --hard" does it (it is just a shell script) is:
	git-read-tree --reset -u $rev

but it does other things for safety. Dave apparently learned git long time before we only had plumbing (set of low-level commands), so the suggestion did not use Porcelain (higher level commands) "git-reset"; back then, the correct way to spell that was:

	git-read-tree $rev &&
        git-checkout-index -f -q -u -a

but git-read-tree learned -u option and made the second command in this sequence unnecessary.

In general, you should not have to use git-checkout-index nor git-read-tree yourself if you are working with today's git.

Previous: Chris Lee
Message 9 of 9 in “Simple UI question...”
  1. Chris LeeJan 7, 2007
  2. Josef "Jeff" SipekJan 7, 2007
  3. Shawn O. PearceJan 7, 2007
  4. Chris LeeJan 7, 2007
  5. Shawn O. PearceJan 7, 2007
  6. Chris LeeJan 7, 2007
  7. Junio C HamanoJan 7, 2007
  8. Chris LeeJan 7, 2007
  9. Junio C HamanoJan 7, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.