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

Re: git-checkout silently throws away the dirty status of index without a warning?

From
Junio C Hamano <gitster@pobox.com>
Date
Sep 1, 2011, 17:11 UTC
Message-ID
<7v1uw0xk57.fsf@alter.siamese.dyndns.org>
In-Reply-To
<CAEvN+1h+mY+f3dzK7LFOwkqokOZSS-LosCzBqtYGbyjz=Dg7Zw@mail.gmail.com>
Tzu-Jung Lee <roylee17@gmail.com> writes:
> Is this an intended behavior?

Yes, I think you are talking about the case where "the current index does not match the current HEAD, but it does match the tree we are switching to" case. In that case we take the contents of switched-to branch.

It is the last case in the table in this old design document:
    http://thread.gmane.org/gmane.comp.version-control.git/4641

bug ignore the terminology (stage#). Read only the body of the table, with the understanding that the three entries in each row talk about the state for the same path in the index entry, the tree entry in the current HEAD, and the tree entry in the switched-to branch. Also the table does not talk about the checking performed on the working tree file, but assume that we do not overwrite it when the resulting entry in the index does not match what you have there.

The reason we allow branch switching in this case, instead of failing, is so that you can be in a state where you applied the same change (relative to the current branch to the branch you are switching to) lying around already in your workspace and safely switch to the new branch without losing any work (after all, the content matches).

By the way, the first six lines of your original message that describes "saving and applying" is not correct.

Previous: Tzu-Jung LeeNext: Tzu-Jung Lee
Message 4 of 6 in “git-checkout silently throws away the dirty status of index without a warning?”
  1. Tzu-Jung LeeSep 1, 2011
  2. Jeff KingSep 1, 2011
  3. Tzu-Jung LeeSep 1, 2011
  4. Junio C HamanoSep 1, 2011
  5. Tzu-Jung LeeSep 1, 2011
  6. Andrew ArdillSep 2, 2011

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.