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.


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)

To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to
More majordomo info at

Reply via email to