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

Re: git stash deletes/drops changes of

From
Thomas Rast <trast@inf.ethz.ch>
Date
May 23, 2013, 22:10 UTC
Message-ID
<87sj1d5ous.fsf@linux-k42r.v.cablecom.net>
In-Reply-To
<loom.20130523T185301-635@post.gmane.org>
Jim Greenleaf <james.a.greenleaf@gmail.com> writes:
Show 9 quoted lines
> Adeodato Simó <dato <at> net.com.org.es> writes:
>
>> I was unpleasantly surprised to discover yesterday that doing `git
>> stash` on a repository where I had previously run `git update-index
>> --assume-unchanged FOO` completely lost all changes I had in file FOO.
>
> I just ran into this today.
>
> Was a decision about this behavior reached in the intervening time?

When you mark a file assume-unchanged, git internally sets a flag that this file should not be considered when doing cache refreshes -- the file is always assumed to be up-to-date.

So while I haven't actually looked into all of the code, I imagine it goes something like this:

* git-stash uses git update-index --all on all modified files.  But it
  doesn't show up as modified, because you promised it isn't.
* Later it calls git reset --hard, which blows away the existing state.
  This would seem to ignore the assume-unchanged flag in this case, as
  otherwise it wouldn't overwrite it.

Whether the last behavior is a bug is in the eye of the beholder. In your case you apparently lost work. However, 'git reset --hard' in itself should discard all uncommitted work without asking any further questions (because it's --hard). So the bug is then in the sequence

  ask about uncommitted work
  save it elsewhere
  git reset --hard

assuming that this actually makes sure nothing gets lost. But the only thing that was lost was *files that you promised would not be changed*.

What's really unfortunate is that we caused this in the first place by Pasky's 6259ac6 (Documentation: How to ignore local changes in tracked files, 2008-07-18). It recommends exactly the --assume-unchanged strategy to ignore changes to tracked files.

And it's hard to disagree with its commit message:
    This is currently probably one of the top FAQs at #git and the
    --assume-unchanged switch is not widely known

Except that now the corresponding FAQ is that we have to actively dissuade people from using --assume-unchanged precisely because it keeps biting people.

So maybe it would be time to first make up our minds as to what --assume-unchanged should actually mean:

* Ignore changes to a tracked file, but treat them as valuable.  In
  this case we'd have to make sure that failures like git-stash's are
  handled properly.
* Ignore changes to a tracked file, as in "who cares if it was changed".
* A very specific optimization for users who know what they are doing.
-- 
Thomas Rast
trast@{inf,student}.ethz.ch
Previous: Jim GreenleafNext: Junio C Hamano
Message 3 of 20 in “git stash deletes/drops changes of "assume-unchanged" files”
  1. Adeodato SimóJun 4, 2010
  2. Jim GreenleafMay 23, 2013
  3. Thomas RastMay 23, 2013
  4. Junio C HamanoMay 23, 2013
  5. Thomas RastMay 23, 2013
  6. Junio C HamanoMay 23, 2013
  7. Phil HordMay 24, 2013
  8. Jim GreenleafMay 24, 2013
  9. John KeepingMay 24, 2013
  10. Jim GreenleafMay 24, 2013
  11. John KeepingMay 24, 2013
  12. Petr BaudisMay 23, 2013
  13. John KeepingMay 24, 2013
  14. Petr BaudisMay 24, 2013
  15. John KeepingMay 24, 2013
  16. Petr BaudisMay 24, 2013
  17. John KeepingMay 24, 2013
  18. Petr BaudisMay 24, 2013
  19. John KeepingMay 24, 2013
  20. Stephen BashMay 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.