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

Re: Stash does not save rename information

From
Kyle Meyer <kyle@kyleam.com>
Date
Dec 14, 2019, 23:00 UTC
Message-ID
<87immizf55.fsf@kyleam.com>
In-Reply-To
<296B296B-EBA0-4F1E-AFEA-ADC232E84656@sixfeetup.com>
Chrissy Wainwright <chrissy@sixfeetup.com> writes:
Show 7 quoted lines
> This seems to be a bug:
>  
> 	1	Use `git mv` to rename a file
> 	2	`git status` shows the file was renamed
> 	3	Stash the changes
> 	4	Pop the stash
> 	5	`git status` shows the file change as deleted/new file instead of a rename

You can see very similar behavior with just a deleted file rather than a deleted/new file pair (which is displayed as a rename depending on your configuration):

    $ git init
    $ touch foo && git add foo && git commit -mfoo
    $ git stash
    $ git stash apply
    Removing foo
    On branch master
    Changes not staged for commit:
    	    deleted:    foo
    no changes added to commit

I believe the key thing is that by default 'git stash {apply,pop}' will apply your change to the working tree but not the index [*]. If you pass the --index flag, you should see the behavior you're after:

    $ git reset --hard
    HEAD is now at c023af6 foo
    $ git stash apply --index
    Removing foo
    On branch master
    Changes to be committed:
    	    deleted:    foo
[*] When I initially tried your example, I was confused that the new
    file was added to the index by default, but it seems new files
    receive special treatment, as Jeff King mentions at
    https://lore.kernel.org/git/20161206142446.5ba3wc625p5o6nct@sigill.intra.peff.net/
Previous: Chrissy WainwrightNext: Kyle Meyer
Message 2 of 6 in “Stash does not save rename information”
  1. Chrissy WainwrightDec 14, 2019
  2. Kyle MeyerDec 14, 2019
  3. Kyle MeyerDec 14, 2019
  4. Chrissy WainwrightDec 16, 2019
  5. Bryan TurnerDec 16, 2019
  6. Jeff KingDec 16, 2019

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.