git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: Dennis Kaarsemaker <dennis@kaarsemaker.net>
Cc: Alan Mackenzie <acm@muc.de>, git@vger.kernel.org
Subject: Re: "git stash pop" is doing an unwanted "git add" when there are conflicts.
Date: Tue, 22 Dec 2015 04:30:33 -0500	[thread overview]
Message-ID: <20151222093032.GA5173@sigill.intra.peff.net> (raw)
In-Reply-To: <1450772258.7937.9.camel@kaarsemaker.net>

On Tue, Dec 22, 2015 at 09:17:38AM +0100, Dennis Kaarsemaker wrote:

> On ma, 2015-12-21 at 14:29 +0000, Alan Mackenzie wrote:
> > Hello, git project.
> > 
> > Last night, whilst clearing out a stale "stash stack", I did "git stash
> > pop".  There were conflicts in two files.
> > 
> > However, all the popped files became staged.  This doesn't normally happen.
> > It was intensely irritating, and required me to do "git reset HEAD" on
> > each of the files, none of which I wanted to commit.
> > 
> > I searched the git-stash man page for this scenario, but found nothing
> > about it.
> > 
> > Surely staging all the files is a bug?
> 
> That depends. A stash is two commits: one for all changes that were in
> the index when you ran 'git stash save' and one for all changes not yet
> in the index. When you pop the stash, these then get restored as staged
> resp. unstaged changes. So if your changes are now all staged, I'd
> wager that they were staged when you ran git stash save.

No, I think there's something else going on. Try this:
  
    git init repo &&
    cd repo &&
    
    echo base >one &&
    echo base >two &&
    git add . &&
    git commit -m base &&
    
    echo stash >one &&
    echo stash >two &&
    git stash &&
    
    echo "==> No conflicts, nothing staged"
    git stash apply &&
    
    git reset --hard &&
    echo changes >two &&
    git commit -am changes &&
    
    echo "==> Conflict stages non-conflicting file 'one'"
    ! git stash apply &&
    git status

It seems to be a side effect of merge-recursive to stage the results,
and in the no-conflict path we explicitly reset the index. For the
conflicting case, it's trickier, because we would want to retain the
unmerged entries.

So I agree it's kind of weird, but the conflicting case is inherently
going to touch the index, and you'd generally have to `git add` to mark
the resolutions (but if you really want to just touch the working tree,
you'd need to `git reset`).

-Peff

  reply	other threads:[~2015-12-22  9:30 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-21 14:29 "git stash pop" is doing an unwanted "git add" when there are conflicts Alan Mackenzie
2015-12-21 20:34 ` Alan Mackenzie
2015-12-22  8:17 ` Dennis Kaarsemaker
2015-12-22  9:30   ` Jeff King [this message]
2015-12-24  9:20     ` Alan Mackenzie
2015-12-29  7:53       ` Jeff King
2015-12-29 19:04         ` Junio C Hamano
2015-12-30  7:13           ` Jeff King
2015-12-29 21:20         ` Alan Mackenzie
2015-12-30  7:02           ` 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=20151222093032.GA5173@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=acm@muc.de \
    --cc=dennis@kaarsemaker.net \
    --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).