All of lore.kernel.org
 help / color / mirror / Atom feed
* "git stash pop" is doing an unwanted "git add" when there are conflicts.
@ 2015-12-21 14:29 Alan Mackenzie
  2015-12-21 20:34 ` Alan Mackenzie
  2015-12-22  8:17 ` Dennis Kaarsemaker
  0 siblings, 2 replies; 10+ messages in thread
From: Alan Mackenzie @ 2015-12-21 14:29 UTC (permalink / raw)
  To: git

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?

-- 
Alan Mackenzie (Nuremberg, Germany).

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: "git stash pop" is doing an unwanted "git add" when there are conflicts.
  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
  1 sibling, 0 replies; 10+ messages in thread
From: Alan Mackenzie @ 2015-12-21 20:34 UTC (permalink / raw)
  To: git

Alan Mackenzie <acm@muc.de> wrote: on Mon, 21 Dec 2015 14:29:54
> 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?

Sorry, forgot to mention I'm using git 2.4.10 on GNU/Linux.

-- 
Alan Mackenzie (Nuremberg, Germany).

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: "git stash pop" is doing an unwanted "git add" when there are conflicts.
  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
  1 sibling, 1 reply; 10+ messages in thread
From: Dennis Kaarsemaker @ 2015-12-22  8:17 UTC (permalink / raw)
  To: Alan Mackenzie, git

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.

-- 
Dennis Kaarsemaker
www.kaarsemaker.net

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: "git stash pop" is doing an unwanted "git add" when there are conflicts.
  2015-12-22  8:17 ` Dennis Kaarsemaker
@ 2015-12-22  9:30   ` Jeff King
  2015-12-24  9:20     ` Alan Mackenzie
  0 siblings, 1 reply; 10+ messages in thread
From: Jeff King @ 2015-12-22  9:30 UTC (permalink / raw)
  To: Dennis Kaarsemaker; +Cc: Alan Mackenzie, git

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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: "git stash pop" is doing an unwanted "git add" when there are conflicts.
  2015-12-22  9:30   ` Jeff King
@ 2015-12-24  9:20     ` Alan Mackenzie
  2015-12-29  7:53       ` Jeff King
  0 siblings, 1 reply; 10+ messages in thread
From: Alan Mackenzie @ 2015-12-24  9:20 UTC (permalink / raw)
  To: Jeff King; +Cc: Dennis Kaarsemaker, git

Hello, Jeff.

On Tue, Dec 22, 2015 at 04:30:33AM -0500, Jeff King wrote:
> 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

Thanks for creating a reproducible test case for me!

> 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`).

>From the point of view of a user, this is suboptimal.  git stash is an
abstraction: the preservation of uncomitted changes for later.  Staging
previously unstaged changes with git stash pop severely damages this
abstraction.

Are there any prospects of this getting fixed?

> -Peff

-- 
Alan Mackenzie (Nuremberg, Germany).

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: "git stash pop" is doing an unwanted "git add" when there are conflicts.
  2015-12-24  9:20     ` Alan Mackenzie
@ 2015-12-29  7:53       ` Jeff King
  2015-12-29 19:04         ` Junio C Hamano
  2015-12-29 21:20         ` Alan Mackenzie
  0 siblings, 2 replies; 10+ messages in thread
From: Jeff King @ 2015-12-29  7:53 UTC (permalink / raw)
  To: Alan Mackenzie; +Cc: Dennis Kaarsemaker, git

On Thu, Dec 24, 2015 at 09:20:38AM +0000, Alan Mackenzie wrote:

> > 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`).
> 
> From the point of view of a user, this is suboptimal.  git stash is an
> abstraction: the preservation of uncomitted changes for later.  Staging
> previously unstaged changes with git stash pop severely damages this
> abstraction.

Yeah, I think I agree. But keep in mind that we have to mention the
conflicts _somewhere_, so we're going to touch the index regardless (and
the user is going to have to erase the conflicts in the index
eventually, either with `git add` or `git reset`).

> Are there any prospects of this getting fixed?

Somebody needs to write a patch. I am not 100% convinced that it
_should_ be fixed, but I am leaning that way. But I am not planning to
work on it myself anytime soon. The best way to get more discussion
going is to post a patch. :)

-Peff

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: "git stash pop" is doing an unwanted "git add" when there are conflicts.
  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
  1 sibling, 1 reply; 10+ messages in thread
From: Junio C Hamano @ 2015-12-29 19:04 UTC (permalink / raw)
  To: Jeff King; +Cc: Alan Mackenzie, Dennis Kaarsemaker, git

Jeff King <peff@peff.net> writes:

> Yeah, I think I agree. But keep in mind that we have to mention the
> conflicts _somewhere_, so we're going to touch the index regardless (and
> the user is going to have to erase the conflicts in the index
> eventually, either with `git add` or `git reset`).

I do not think there is much we can do at this point in time (but
notice that I did say "much", and didn't say "anything").

The way we replay any potentially conflicting change and present the
result to the end user in Git is uniformly to add the cleanly
applied parts to the index while leaving the conflicted ones as
unmerged index entries, but "git stash apply/pop" does not follow
this pattern.  I think this is partly because the command is also
used to "stash away" a work-in-progress changes to the index, and
avoiding to touch the index with the changes in the working tree
would more closely match the behaviour of the command when there is
no conflict.

I notice that I said the same thing long time ago, i.e. in the
initial round of review:

  http://article.gmane.org/gmane.comp.version-control.git/50749

| However, I think it is a bit counterintuitive to update the
| working tree change to the index if the merge did not conflict.
| It might be better to run an equivalent of "git reset", so that
| after "git save restore", the user can say "git diff" (not "git
| diff HEAD") to view the local changes.  Perhaps...

In the above, I suggested to "git reset" when there is no conflict.
I think this line of thinking can be followed even further to
selectively reset the paths that were cleanly merged (which is added
by the call to merge-recursive), leaving _only_ the conflicted paths.

Would that give us a better outcome?  I dunno.

>> Are there any prospects of this getting fixed?
>
> Somebody needs to write a patch. I am not 100% convinced that it
> _should_ be fixed, but I am leaning that way. But I am not planning to
> work on it myself anytime soon. The best way to get more discussion
> going is to post a patch. :)

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: "git stash pop" is doing an unwanted "git add" when there are conflicts.
  2015-12-29  7:53       ` Jeff King
  2015-12-29 19:04         ` Junio C Hamano
@ 2015-12-29 21:20         ` Alan Mackenzie
  2015-12-30  7:02           ` Jeff King
  1 sibling, 1 reply; 10+ messages in thread
From: Alan Mackenzie @ 2015-12-29 21:20 UTC (permalink / raw)
  To: Jeff King; +Cc: Dennis Kaarsemaker, git

Hello, Jeff.

On Tue, Dec 29, 2015 at 02:53:30AM -0500, Jeff King wrote:
> On Thu, Dec 24, 2015 at 09:20:38AM +0000, Alan Mackenzie wrote:

> > > 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`).

> > From the point of view of a user, this is suboptimal.  git stash is an
> > abstraction: the preservation of uncomitted changes for later.  Staging
> > previously unstaged changes with git stash pop severely damages this
> > abstraction.

> Yeah, I think I agree. But keep in mind that we have to mention the
> conflicts _somewhere_, so we're going to touch the index regardless (and
> the user is going to have to erase the conflicts in the index
> eventually, either with `git add` or `git reset`).

When the stash consists entirely of changes in the working directory,
and "git stash pop" has conflicts, why can't these conflicts simply be
marked by "<<<<<<<<" (etc.) in the working directory, leaving the index
unchanged?  The index is left unchanged when there are no conlicts.

> > Are there any prospects of this getting fixed?

> Somebody needs to write a patch. I am not 100% convinced that it
> _should_ be fixed, but I am leaning that way. But I am not planning to
> work on it myself anytime soon. The best way to get more discussion
> going is to post a patch. :)

Hmm.  I would very much prefer to remain just a user of git.

> -Peff

-- 
Alan Mackenzie (Nuremberg, Germany).

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: "git stash pop" is doing an unwanted "git add" when there are conflicts.
  2015-12-29 21:20         ` Alan Mackenzie
@ 2015-12-30  7:02           ` Jeff King
  0 siblings, 0 replies; 10+ messages in thread
From: Jeff King @ 2015-12-30  7:02 UTC (permalink / raw)
  To: Alan Mackenzie; +Cc: Dennis Kaarsemaker, git

On Tue, Dec 29, 2015 at 09:20:38PM +0000, Alan Mackenzie wrote:

> > Yeah, I think I agree. But keep in mind that we have to mention the
> > conflicts _somewhere_, so we're going to touch the index regardless (and
> > the user is going to have to erase the conflicts in the index
> > eventually, either with `git add` or `git reset`).
> 
> When the stash consists entirely of changes in the working directory,
> and "git stash pop" has conflicts, why can't these conflicts simply be
> marked by "<<<<<<<<" (etc.) in the working directory, leaving the index
> unchanged?  The index is left unchanged when there are no conlicts.

I don't think that's a good idea. Git always marks conflicts in the
index for other operations. Besides being inconsistent with the rest of
git, it drops useful information that other tools can use. For example,
one cannot "git checkout --conflict=diff3" afterwards, or use "git
mergetool" to kick off a third-party merge tool.

Not to mention that the information is lost to the user themselves. If
we touched 10 files and 2 had conflicts, there is now no way for the
user to ask "where were the conflicts?". They can either find the stash
output in their terminal scrollback, or grep for things that look like
conflict markers.

-Peff

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: "git stash pop" is doing an unwanted "git add" when there are conflicts.
  2015-12-29 19:04         ` Junio C Hamano
@ 2015-12-30  7:13           ` Jeff King
  0 siblings, 0 replies; 10+ messages in thread
From: Jeff King @ 2015-12-30  7:13 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Alan Mackenzie, Dennis Kaarsemaker, git

On Tue, Dec 29, 2015 at 11:04:20AM -0800, Junio C Hamano wrote:

> [...]
> In the above, I suggested to "git reset" when there is no conflict.
> I think this line of thinking can be followed even further to
> selectively reset the paths that were cleanly merged (which is added
> by the call to merge-recursive), leaving _only_ the conflicted paths.
> 
> Would that give us a better outcome?  I dunno.

Yes, I think that is the only sensible change to make. The only other
option (besides leaving it as-is) would be to unstage _everything_
leaving conflict-marker cruft in the working tree, but no conflicts in
the index. I think that's a mistake, but I won't repeat the arguments I
left elsewhere in the thread.

So it's probably something like:

  git ls-files -t |
  grep -v ^M |
  cut -d ' ' -f2- |
  xargs git reset --

(modulo some quoting robustness improvements). But I guess we'd want to
preserve any modifications that were originally in the index. So maybe
the intersection of the files above and the output of "git diff-tree
--name-only" on the stash commit.

There are probably some corner cases to look at (e.g., with "--index").

As I said, I'm not planning to work on it anytime soon, but the above
may give some clues to somebody who wants to pursue it.

-Peff

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2015-12-30  7:14 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.