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

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

From
Rr.ductor@gmail.com <r.ductor@gmail.com>
Date
Sep 24, 2013, 09:25 UTC
Message-ID
<1753009.aAamh0ufex@ipht-ia-004976>
In-Reply-To
<xmqq1u4jp0bw.fsf@gitster.dls.corp.google.com>
Dear Juno
Thanks for your answer.
My fair criticism in my previous emails (and below) is just to try to convince you that with a few short sentences you risk to transmit only vague ideas, while a serious user is interested to understand the behavior of git in any occurrence, with no ambiguity. Once more, in my view a short pseudo code -- or its equivalent in words -- would be a useful compromise among simplicity and accuracy.
I'm attacking git checkout but I guess that what I say is a general problem of the git official documentation (i.e git stash in my experience has problems).
Each undocumented feature (simulated by my dumb questions) enforces the loss of a significant percentage of the users.
Lacking details, a hurried user will not use the feature, or if they are brave enough, they will use it without understanding (i.e. risking data loss one day or the other)...
Lacking details, a serious user will have to waste their time in trials or in studing the sources.
Do not fear that giving details in a man page would scare newbyes: as a git newbye I can say that what scares me is the lack of information, not the complexity(=power) of a program (*)
Do not waste your precious time in explaining me/us general ideas, we can find them in the tens of pedagogic tutorials/books out there, please give us those details that nobody out there seems to know and that man (un)intentionally hides!
I would be happy to submit a patch for the man git-checkout but I'm not sure that my understanding of git checkout (as encoded in the pseudocode I submitted) is correct.
My friendly regards,
ric
(*) of course you're allowed to discard my suggestions pretending that I'm not a representative user ;)
On Friday 20 September 2013 15:58:27 Junio C Hamano wrote:
Show 5 quoted lines
> The principle is that we allow you to check out a different branch
> when you have local changes to the working tree and/or to the index,
> as long as we can make the index and the working tree pretend as if
> you reached that locally modified state, starting from a clean state
> of the branch you are checking out.
Of course I understand the idea, but if I try to grasp the details I'm in trouble: the problem in this statement is the ambiguity of "change" and "pretend as".
In plain english I can start from any content and change it to any other content, so in this semantics your statement is empty, or worse.
If I assume that change means "differences with N lines of unchanged context" I must still guess differences with respect to what? head-index, index-work, head-work ???? ... and how much is N? 3, 4, 1028?
Then, in order to understand I (a user) make the trials below, and concludes that also the nice principle stated above is somewhat incomplete....
git-test15$ echo -e 'a\n1\n2\n3\n4\n5\nb\n6\n7\n8\n9\n10\n'>f; cat f;git init; git add f; git commit -a -m 'ab'; git checkout -b dev; echo -e 'A\n1\n2\n3\n4\n5\nb\n6\n7\n8\n9\n10\n'>f;cat f;git commit -a -m 'Ab'; echo -e 'A\n1\n2\n3\n4\n5\nB\n6\n7\n8\n9\n10\n'>f;cat f;git add f; git checkout master                                                                            
a                                                                                                                                      
1                                                                                                                                      
2                                                                                                                                      
3                                                                                                                                      
4                                                                                                                                      
5                                                                                                                                      
b                                                                                                                                      
6                                                                                                                                      
7                                                                                                                                      
8                                                                                                                                      
9                                                                                                                                      
10                                                                                                                                     
                                                                                                                                       
Initialized empty Git repository in /home/git-test15/.git/                                                                 
[master (root-commit) 46d19ab] ab                                                                                                      
 1 file changed, 13 insertions(+)                                                                                                      
 create mode 100644 f                                                                                                                  
Switched to a new branch 'dev'                                                                                                         
A                                                                                                                                      
1
2
3
4
5
b
6
7
8
9
10
[dev bb852db] Ab
 1 file changed, 1 insertion(+), 1 deletion(-)
A
1
2
3
4
5
B
6
7
8
9
10
error: Your local changes to the following files would be overwritten by checkout:
        f
Please, commit your changes or stash them before you can switch branches.
Aborting

##################################################################################### #### why abort the change w.r.t. dev was just b -> B and that patch was admissible in master ... I start questioning the principle #### #####################################################################################

git-test15$ mkdir ../gittest16 git-test15$ cd ../gittest16 gittest16$ echo -e 'a\n1\n2\n3\n4\n5\nb\n6\n7\n8\n9\n10\n'>f; cat f;git init; git add f; git commit -a -m 'ab'; git checkout -b dev; echo -e 'A\n1\n2\n3\n4\n5\nb\n6\n7\n8\n9\n10\n'>f;cat f;git commit -a -m 'Ab'; echo -e 'a\n1\n2\n3\n4\n5\nB\n6\n7\n8\n9\n10\n'>f;cat f;git add f; git checkout master a 1 2 3 4 5 b 6 7 8 9 10

Initialized empty Git repository in /home/gittest16/.git/
[master (root-commit) 7d7febe] ab
 1 file changed, 13 insertions(+)
 create mode 100644 f
Switched to a new branch 'dev'
A
1
2
3
4
5
b
6
7
8
9
10
[dev 143db1d] Ab
 1 file changed, 1 insertion(+), 1 deletion(-)
a
1
2
3
4
5
B
6
7
8
9
10
error: Your local changes to the following files would be overwritten by checkout:
        f
Please, commit your changes or stash them before you can switch branches.
Aborting
gittest16$

##################################################################################### #### why abort? the change w.r.t. master was just b -> B and that patch was admissible in master ... I start questioning the principle #### #####################################################################################

Previous: Junio C Hamano
Message 5 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.