git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Kyle Meyer <kyle@kyleam.com>
To: Chrissy Wainwright <chrissy@sixfeetup.com>,
	"git\@vger.kernel.org" <git@vger.kernel.org>
Subject: Re: Stash does not save rename information
Date: Sat, 14 Dec 2019 23:00:38 +0000	[thread overview]
Message-ID: <87immizf55.fsf@kyleam.com> (raw)
In-Reply-To: <296B296B-EBA0-4F1E-AFEA-ADC232E84656@sixfeetup.com>

Chrissy Wainwright <chrissy@sixfeetup.com> writes:

> 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/

  reply	other threads:[~2019-12-14 23:00 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-14 19:41 Stash does not save rename information Chrissy Wainwright
2019-12-14 23:00 ` Kyle Meyer [this message]
2019-12-14 23:05   ` Kyle Meyer
2019-12-16 14:32     ` Chrissy Wainwright
2019-12-16 18:42       ` Bryan Turner
2019-12-16 19:25       ` Jeff King

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87immizf55.fsf@kyleam.com \
    --to=kyle@kyleam.com \
    --cc=chrissy@sixfeetup.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).