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

Re: My first git success [not quite]

From
Linus Torvalds <torvalds@osdl.org>
Date
Jan 14, 2006, 21:57 UTC
Message-ID
<Pine.LNX.4.64.0601141350590.13339@g5.osdl.org>
In-Reply-To
<dqbnl1$3si$1@sea.gmane.org>
On Sat, 14 Jan 2006, walt wrote:
Show 12 quoted lines
>
> Linus Torvalds wrote:
> [...]
> > Now, what happens is that when you change branches with a dirty tree, the 
> > "git checkout" will do one of two things:
> > 
> >  - if the dirty files are _identical_ in both branches...
> 
> I'm sorry to be quibbling over semantics, truly I am!  But here
> is my confusion:  if modified-but-uncommitted (hence dirty) files
> are not associated with *any* branch, then how could 'dirty' files
> be 'in' both branches (or 'in' any branch at all)?

The file itself is associated with the branch. It's just that the _dirty_ part isn't.

Of course, you can also truly have files that aren't associated with either branch at all: files that haven't gotten committed at all. They're also "dirty state", and exactly like modifications to known files, they are carried along with the switch, so they'll exist in the directory tree after a "git checkout".

Anyway, in git, a "branch" is technically really nothing more than "top of a commit chain". If you look into the files that describe a branch, you'll literally just find the name of the top commit. Do a

	cat .git/refs/heads/master
to see. 

So anything that isn't described by that commit is by definition "dirty state", whether it's because you've edited something (but not checked it in) or because there's some random generated file in the working tree.

So when you switch branches, you really should think of it as "ok, the committed state was switched around", and everything else was just "moved along".

		Linus
Previous: Junio C HamanoNext: Junio C Hamano
Message 14 of 15 in “My first git success”
  1. waltJan 13, 2006
  2. Linus TorvaldsJan 13, 2006
  3. Randal L. SchwartzJan 13, 2006
  4. Junio C HamanoJan 13, 2006
  5. Peter EriksenJan 13, 2006
  6. waltJan 14, 2006
  7. seanJan 14, 2006
  8. waltJan 14, 2006
  9. Randal L. SchwartzJan 14, 2006
  10. Junio C HamanoJan 14, 2006
  11. Linus TorvaldsJan 14, 2006
  12. waltJan 14, 2006
  13. Junio C HamanoJan 14, 2006
  14. Linus TorvaldsJan 14, 2006
  15. Junio C HamanoJan 15, 2006

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.