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

Re: for newbs = little exercise / tutorial / warmup for windows and other non-sophisticated new Git users :-) [Scanned]

From
Daniel Barkalow <barkalow@iabervon.org>
Date
Dec 31, 2008, 16:24 UTC
Message-ID
<alpine.LNX.1.00.0812311103000.19665@iabervon.org>
In-Reply-To
<gjfnsb$5ph$4@ger.gmane.org>
On Wed, 31 Dec 2008, Zorba wrote:
Show 10 quoted lines
> Ok, now I'm following you, cos I just "broke" checkout again by deleting 
> files from working dirs before running it.
> 
> git-checkout takes into account the state of the working tree in the commit 
> it is run FROM, as well as the commit it is checking out.
> 
> It relies on the working tree being in synch with the commit it is run from.
> If I delete files, I screw around with this initial state.
> Files that git-checkout is relying on to be there are not copied in by it, 
> so if I've deleted (or modified) those files, hard luck.

It's not relying on these files to be there; it's actually aware that they're not there. It thinks that any modifications you've made might be important work, and carefully preserves it.

Actually, it should be telling you the changes that it's carrying over with lines like:

D	ABC.txt

(which indicated that you've deleted ABC.txt, and it's keeping that modification)

> I remember s/o saying git minimizes file I/O, and this whats happening here.
> 
> It puts a big demand on the user, to keep their index & working dir in synch 
> with whats in the commit.

The user is hopefully not going to make a lot of random undesired changes in general. It's hard to get much done that way. If you have made changes, you can use "git checkout ." to get the versions back from the index, or "git checkout HEAD ." to get them back from the commit.

Show 14 quoted lines
> Ah,
> 
> $ git checkout .
> 
> will restore the state of the working dir to be in synch with the CURRENT 
> commit, so it will be safe to checkout other branches
> 
> BINGO !!
> what I need to do is run the sequence
> 
> $ git checkout .                    // tidy up current commit
> $ git checkout <version>     // roll back
> 
> n'est pas ?
Either that, or:

$ git checkout <version> $ git checkout .

(it doesn't matter whether you get rid of the local modifications and deletions before switching, or switch first, and then get rid of any remaining local modifications and deletions)

You may also want:
$ git clean

To get rid of untracked files you may have around (use "git clean -x" if you also want to get rid of files you've told git to ignore).

Incidentally, if your goal is to give someone a copy of the state as of a particular version, you can use:

$ git archive --format=zip <commit> > version.zip

This doesn't involve your working directory at all, and just generates a zip file out of the history. I find that this means I rarely actually care about having a working directory that's free of random junk.

	-Daniel
*This .sig left intentionally blank*
Previous: Sitaram ChamartyNext: Sitaram Chamarty
Message 8 of 11 in “RE: for newbs = little exercise / tutorial / warmup for windows and other non-sophisticated new Git users :-) [Scanned]”
  1. Conor RaffertyDec 31, 2008
  2. Jeff WhitesideDec 31, 2008
  3. Boyd Stephen Smith Jr.Dec 31, 2008
  4. Daniel BarkalowDec 31, 2008
  5. Daniel BarkalowDec 31, 2008
  6. ZorbaDec 31, 2008
  7. Sitaram ChamartyDec 31, 2008
  8. Daniel BarkalowDec 31, 2008
  9. Sitaram ChamartyDec 31, 2008
  10. ZorbaDec 31, 2008
  11. Sitaram ChamartyDec 31, 2008

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.