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

On the behavior of checkout <branch> with uncommitted local changes

From
Rr.ductor@gmail.com <r.ductor@gmail.com>
Date
Sep 19, 2013, 09:23 UTC
Message-ID
<8904036.vOg3y5OkbU@ipht-ia-004976>
Dear all
I'm not a power git user but I profit of git every day and I like to fully understand what I do.
The man section for git checkout is too vague for my taste. In particular it is not clearly (unambiguously) stated what happens to index and worktree whenever local uncommitted changes are around. I've already rised a similar problem in this mail list [1], but I understand that a man page must be concise.
On the other hand, I couldn't find any complete information on this behavior: tutorials and books seem to avoid the problem, user posts seems confused ... 
To grasp some more information,  I've spent some hours in trials (sorry I'm unable to grasp information browsing the code repository). That resulted in the algorithm below presented.
Could anybody authoritative on that subject confirm/correct/discharge my statement? That could be of help for me and may others.
Nonetheless to say having this kind of pseudocodes available somewhere (e.g. for stash [2] and other tools modifing index and working tree) would make my git experience  (and that of many more people) happier.
Thanks to all developers for their efforts.

Regards ric

Notations: let us fix a file and denote
C0  = its version in the initial commit
I0   = its version in the initial index
W0 = its version in the working tree
C1 = its version in the target commit
W1= its version in working tree after checkout completed
I1  = its version in index after checkout completed
git checkout Branch

if C0=W0=I0, then: W1=I1=C1; if C1=I0, then: W1=W0 and I1=C1=I0; if C1=C0, then: W1=W0 and I1=I0; otherwise: abort

Note: in particular, if W0=I0 !=C0 then (in general) abort
Note: in particular, if C0=I0 and C1=W0 then abort  (...actually why that? no information is lost)

REFS [1]http://thread.gmane.org/gmane.linux.debian.devel.bugs.general/782914/focus=164647 [2]http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=717088

Next: Junio C Hamano
Message 1 of 5 in “On the behavior of checkout <branch> with uncommitted local changes”
  1. r.ductor@gmail.comSep 19, 2013
  2. Junio C HamanoSep 19, 2013
  3. r.ductor@gmail.comSep 20, 2013
  4. Junio C HamanoSep 20, 2013
  5. r.ductor@gmail.comSep 24, 2013

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.