Skip to contentSkip to conversation

`git stash pop` UX Problem

DISCUSSION Omar Othman 11 participants 46 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

Hi there,

I'm fairly new to git and I wanted to ask about a certain behavior that I want to fix myself (if you agree with me that it is a misbehavior)... since I've never contributed to open source and it'll be an important step for me to start and get something done.

In general, whenever something a user "should" do, git always tells. So, for example, when things go wrong with a merge, you have the option to abort. When you are doing a rebase, git tells you to do git commit --amend, and then git rebase --continue... and so on.

The point is: Because of this, git is expected to always instruct you on what to do next in a multilevel operation, or instructing you what to do when an operation has gone wrong.

Now comes the problem. When you do a git stash pop, and a merge conflict happens, git correctly tells you to fix the problems and then git add to resolve the conflict. But once that happens, and the internal status of git tells you that there are no more problems (I have a prompt that tells me git's internal status), the operation is not culminated by dropping the stash reference, which what normally happens automatically after a git stash pop. This has actually confused me for a lot of time, till I ran into a git committer and asked him, and only then were I 100% confident that I did nothing wrong and it is indeed a UX problem. I wasted a lot of time to know why the operation is not completed as expected (since I trusted that git just does the right thing), and it turned out that it is git's fault.

If this is accepted, please reply to this email and tell me to start working on it. I've read the Documenation/SubmittingPatches guidelines, but I'll appreciate also telling me where to base my change. My guess is maint, since it's a "bug" in the sense of UX.

Thanks and sorry for the long email.

#1 lore raw

Omar:

Quoted 21 lines · Omar Othman

In general, whenever something a user "should" do, git always tells. So, for example, when things go wrong with a merge, you have the option to abort. When you are doing a rebase, git tells you to do git commit --amend, and then git rebase --continue... and so on.

The point is: Because of this, git is expected to always instruct you on what to do next in a multilevel operation, or instructing you what to do when an operation has gone wrong.

Now comes the problem. When you do a git stash pop, and a merge conflict happens, git correctly tells you to fix the problems and then git add to resolve the conflict. But once that happens, and the internal status of git tells you that there are no more problems (I have a prompt that tells me git's internal status), the operation is not culminated by dropping the stash reference, which what normally happens automatically after a git stash pop. This has actually confused me for a lot of time, till I ran into a git committer and asked him, and only then were I 100% confident that I did nothing wrong and it is indeed a UX problem. I wasted a lot of time to know why the operation is not completed as expected (since I trusted that git just does the right thing), and it turned out that it is git's fault.

Quoted 4 lines

If this is accepted, please reply to this email and tell me to start working on it. I've read the Documenation/SubmittingPatches guidelines, but I'll appreciate also telling me where to base my change. My guess is maint, since it's a "bug" in the sense of UX.

Unlike a merge, when you pop a stash that history is lost. If you screw up the merge and the stash is dropped then there's generally no reliable way to get it back. I think that it's correct behavior for the stash to not be dropped if the merge conflicts. The user is expected to manually drop the stash when they're done with it. It's been a while since I've relied much on the stash (commits and branches are more powerful to work with) so I'm not really familiar with what help the UI gives when a conflict occurs now. Git's UI never really expects the user to be negligent. It does help to hint to you what is needed, but for the most part it still expects you to know what you're doing and does what you say, not what you mean.

If there's any change that should be made it should be purely providing more detailed instructions to the user about how to deal with it. Either resolve the merge conflicts and git-add the conflicting files, or use git-reset to either reset the index (unstaging files nad clear) or reset index and working tree back to HEAD. In general, I almost always git-reset after a git-stash pop because I'm probably not ready to commit those changes yet and generally want to still see those changes with git diff (without --staged). Or perhaps just direct them to the appropriate sections of the man pages.

I'm not really in favor of "dumbing down" Git in any way and I think that any step in that direction would be for the worst... Software should do what you say, not what you mean, because it's impossible to reliably guess what you meant. When a git-stash pop operation fails that might make the user rethink popping that stash. That's why it becomes a manual operation to drop it if still desired. And unlike git-reset --continue, which is explicitly the user saying "it is fixed and I accept the consequences, let's move on", there is no such option to git-stash to acknowledge that the merge conflicts have been resolved and you no longer need that stash (aside from git-stash drop, of course). It's not a UI problem. It's maybe a documentation problem, but again I'm not familiar with the current state of that.

/not a git dev...yet

Regards,

Signature · 6 lines
Brandon McCaig <[email protected]> <[email protected]>
Castopulence Software <https://www.castopulence.org/>
Blog <http://www.bamccaig.com/>
perl -E '$_=q{V zrna gur orfg jvgu jung V fnl. }.
q{Vg qbrfa'\''g nyjnlf fbhaq gung jnl.};
tr/A-Ma-mN-Zn-z/N-Zn-zA-Ma-m/;say'
#2 lore raw

Brandon:

Please note that what I am asking for is not always dropping the stash, but doing that *only* when the merge conflict is resolved. This is simply getting the whole command to be consistent. If you do git stash pop and it succeeds, the stash reference is dropped. If you do git stash pop and it succeeds *after resolving the merge conflict*, the stash reference is *not* dropped. This is *not* consistent and *is* a user experience problem. I'm not asking about dumbing git down by any means.

Quoted 69 lines · Brandon McCaig

Omar:

Quoted 21 lines · Omar Othman

In general, whenever something a user "should" do, git always tells. So, for example, when things go wrong with a merge, you have the option to abort. When you are doing a rebase, git tells you to do git commit --amend, and then git rebase --continue... and so on.

The point is: Because of this, git is expected to always instruct you on what to do next in a multilevel operation, or instructing you what to do when an operation has gone wrong.

Now comes the problem. When you do a git stash pop, and a merge conflict happens, git correctly tells you to fix the problems and then git add to resolve the conflict. But once that happens, and the internal status of git tells you that there are no more problems (I have a prompt that tells me git's internal status), the operation is not culminated by dropping the stash reference, which what normally happens automatically after a git stash pop. This has actually confused me for a lot of time, till I ran into a git committer and asked him, and only then were I 100% confident that I did nothing wrong and it is indeed a UX problem. I wasted a lot of time to know why the operation is not completed as expected (since I trusted that git just does the right thing), and it turned out that it is git's fault.

Quoted 4 lines

If this is accepted, please reply to this email and tell me to start working on it. I've read the Documenation/SubmittingPatches guidelines, but I'll appreciate also telling me where to base my change. My guess is maint, since it's a "bug" in the sense of UX.

Unlike a merge, when you pop a stash that history is lost. If you screw up the merge and the stash is dropped then there's generally no reliable way to get it back. I think that it's correct behavior for the stash to not be dropped if the merge conflicts. The user is expected to manually drop the stash when they're done with it. It's been a while since I've relied much on the stash (commits and branches are more powerful to work with) so I'm not really familiar with what help the UI gives when a conflict occurs now. Git's UI never really expects the user to be negligent. It does help to hint to you what is needed, but for the most part it still expects you to know what you're doing and does what you say, not what you mean.

If there's any change that should be made it should be purely providing more detailed instructions to the user about how to deal with it. Either resolve the merge conflicts and git-add the conflicting files, or use git-reset to either reset the index (unstaging files nad clear) or reset index and working tree back to HEAD. In general, I almost always git-reset after a git-stash pop because I'm probably not ready to commit those changes yet and generally want to still see those changes with git diff (without --staged). Or perhaps just direct them to the appropriate sections of the man pages.

I'm not really in favor of "dumbing down" Git in any way and I think that any step in that direction would be for the worst... Software should do what you say, not what you mean, because it's impossible to reliably guess what you meant. When a git-stash pop operation fails that might make the user rethink popping that stash. That's why it becomes a manual operation to drop it if still desired. And unlike git-reset --continue, which is explicitly the user saying "it is fixed and I accept the consequences, let's move on", there is no such option to git-stash to acknowledge that the merge conflicts have been resolved and you no longer need that stash (aside from git-stash drop, of course). It's not a UI problem. It's maybe a documentation problem, but again I'm not familiar with the current state of that.

/not a git dev...yet

Regards,

#3 lore raw
Quoted 1 line · Omar Othman

Brandon:

Please, don't top-post on this list. Look how other people answer to each other and follow the use.

Quoted 8 lines

Please note that what I am asking for is not always dropping the stash, but doing that *only* when the merge conflict is resolved. This is simply getting the whole command to be consistent. If you do git stash pop and it succeeds, the stash reference is dropped. If you do git stash pop` and it succeeds *after resolving the merge conflict*, the stash reference is *not* dropped. This is *not* consistent and *is* a user experience problem. I'm not asking about dumbing git down by any means.

Can you describe precisely what you would expect, e.g. what Git's output should look like after such and such command?

Signature · 2 lines
Matthieu Moy
http://www-verimag.imag.fr/~moy/
#4 lore raw
Quoted 11 lines
Quoted 9 lines

Please note that what I am asking for is not always dropping the stash, but doing that *only* when the merge conflict is resolved. This is simply getting the whole command to be consistent. If you do git stash pop and it succeeds, the stash reference is dropped. If you do git stash pop` and it succeeds *after resolving the merge conflict*, the stash reference is *not* dropped. This is *not* consistent and *is* a user experience problem. I'm not asking about dumbing git down by any means.

Can you describe precisely what you would expect, e.g. what Git's output should look like after such and such command?

Sure. This is my current command prompt (which shows git's internal status):

[omar_othman main (trunk*)]$

I do a git stash pop, which causes a merge conflict:

Auto-merging path/to/file.txt
CONFLICT (content): Merge conflict in path/to/file.txt

[omar_othman main (trunk|MERGING*)]$ vi path/to/file.txt [omar_othman main (trunk|MERGING*)]$ git add path/to/file.txt [omar_othman main (trunk*)]$

Note how the status message has changed to show that git is now happy. It is at that moment that the stash reference should be dropped (or the user (somehow) is notified to do that herself if desired), because this means that the popping operation has succeeded.

#5 lore raw
Quoted 5 lines · Omar Othman

[omar_othman main (trunk|MERGING*)]$ git add path/to/file.txt [omar_othman main (trunk*)]$

Note how the status message has changed to show that git is now happy. It is at that moment that the stash reference should be dropped

Dropping the stash on a "git add" operation would be really, really weird...

Quoted 2 lines

(or the user (somehow) is notified to do that herself if desired), because this means that the popping operation has succeeded.

But how would you expect to "be notified"?

Signature · 2 lines
Matthieu Moy
http://www-verimag.imag.fr/~moy/
#32 lore raw
In reply to Brandon McCaig
Quoted 4 lines · Brandon McCaig

Unlike a merge, when you pop a stash that history is lost. If you screw up the merge and the stash is dropped then there's generally no reliable way to get it back. I think that it's correct behavior for the stash to not be dropped if the merge conflicts.

Agreed.

Quoted 3 lines

If there's any change that should be made it should be purely providing more detailed instructions to the user about how to deal with it.

Yes, there may be room for improvement, but that does not seem so easy. Today, we have:

$ git stash pop
Auto-merging foo.txt
CONFLICT (content): Merge conflict in foo.txt
$ git status
On branch master
Unmerged paths:
  (use "git reset HEAD <file>..." to unstage)
  (use "git add <file>..." to mark resolution)

both modified: foo.txt

=> The advices shown here are OK. Then:

$ git add foo.txt 
$ git status
On branch master
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

modified: foo.txt

=> here, "git status" could have hinted the user "you may now run 'git stash drop' if you are satisfied with your merge".

An obvious issue is that at this point Git has no way to know that you just did a "git stash pop". But that could be solved by leaving a file around like .git/stash-pop-ongoing.

Now, the real question is: when would Git stop showing this advice. I don't see a real way to answer this, and I'd rather avoid doing just a guess.

One easy thing to do OTOH would be to show a hint at the end of "git stash pop"'s output, like

$ git stash pop
Auto-merging foo.txt
CONFLICT (content): Merge conflict in foo.txt
'stash pop' failed. Please, resolve the conflicts manually. The stash
was not dropped in case you need to restart the operation. When you are
done resolving the merge, you may run the following to drop the stash:

git stash drop

or so (I couldn't find a concise yet accurate wording).

Signature · 2 lines
Matthieu Moy
http://www-verimag.imag.fr/~moy/
#33 lore raw

Am 24.02.2014 17:21, schrieb Matthieu Moy:

Quoted 7 lines
$ git add foo.txt
$ git status
On branch master
Changes to be committed:
   (use "git reset HEAD <file>..." to unstage)

modified: foo.txt

Maybe status should display a stash count if that count is > 0, as this is part of the state of the repo.

$ git status
On branch master
Stashes: 1                         <----------
Changes to be committed:
    (use "git reset HEAD <file>..." to unstage)

modified: foo.txt

It would be in Omars example case a clear message that git kept the stash. And generally a reminder that there is still a stash around that might or might not be obsolete.

#34 lore raw
Quoted 11 lines · Holger Hellmuth

Am 24.02.2014 17:21, schrieb Matthieu Moy:

Quoted 7 lines
$ git add foo.txt
$ git status
On branch master
Changes to be committed:
   (use "git reset HEAD <file>..." to unstage)

modified: foo.txt

Maybe status should display a stash count if that count is > 0, as this is part of the state of the repo.

Maybe it would help some users, but not me for example. My main use of "git stash" is a safe replacement for "git reset --hard": when I want to discard changes, but keep them safe just in case.

So, my stash count is almost always >0, and I don't want to hear about it.

Signature · 2 lines
Matthieu Moy
http://www-verimag.imag.fr/~moy/
#35 lore raw

Well, it's called git stash and not git trash... :-D

That's your own usage of it, but its main usage is different.

This is not a solution, but it's better than nothing and I second it.

Quoted 18 lines · Matthieu Moy
Quoted 10 lines · Holger Hellmuth

Am 24.02.2014 17:21, schrieb Matthieu Moy:

Quoted 7 lines
$ git add foo.txt
$ git status
On branch master
Changes to be committed:
    (use "git reset HEAD <file>..." to unstage)

modified: foo.txt

Maybe status should display a stash count if that count is > 0, as this is part of the state of the repo.

Maybe it would help some users, but not me for example. My main use of "git stash" is a safe replacement for "git reset --hard": when I want to discard changes, but keep them safe just in case.

So, my stash count is almost always >0, and I don't want to hear about it.

#36 lore raw
In reply to Matthieu Moy
Quoted 14 lines · Matthieu Moy
Quoted 11 lines · Holger Hellmuth

Am 24.02.2014 17:21, schrieb Matthieu Moy:

Quoted 7 lines
$ git add foo.txt
$ git status
On branch master
Changes to be committed:
   (use "git reset HEAD <file>..." to unstage)

modified: foo.txt

Maybe status should display a stash count if that count is > 0, as this is part of the state of the repo.

Quoted 6 lines

Maybe it would help some users, but not me for example. My main use of "git stash" is a safe replacement for "git reset --hard": when I want to discard changes, but keep them safe just in case.

So, my stash count is almost always >0, and I don't want to hear about it.

"status" is about reminding the user what changes are already in the index (i.e. what you would commit) and what changes are in the working tree, from which you could further update the index with (i.e. what you could commit).

One _could_ argue that stashed changes are what could be reflected to the working tree and form the source of the latter, but my gut feeling is that it is a rather weak argument. At that point you are talking about what you could potentially change in the working tree, and the way to do so is not limited to "stash pop" (i.e. you can "git cherry-pick --no-commit $a_commit", or "edit" any file in the working tree for that matter, with the same ease).

So, I tend to agree with you, while I do understand where "I want to know about what is in stash" is coming from (and that is why we do have "git stash list" command).

#6 lore raw
In reply to Matthieu Moy
Quoted 4 lines
Quoted 4 lines

[omar_othman main (trunk|MERGING*)]$ git add path/to/file.txt [omar_othman main (trunk*)]$

Quoted 8 lines
Quoted 2 lines

Note how the status message has changed to show that git is now happy. It is at that moment that the stash reference should be dropped

Dropping the stash on a "git add" operation would be really, really weird...

Quoted 2 lines

(or the user (somehow) is notified to do that herself if desired), because this means that the popping operation has succeeded.

But how would you expect to "be notified"?

Answering the last question, your previous comments are fine with me:

Quoted 26 lines
Quoted 3 lines

If there's any change that should be made it should be purely providing more detailed instructions to the user about how to deal with it.

Yes, there may be room for improvement, but that does not seem so easy. Today, we have:

$ git stash pop
Auto-merging foo.txt
CONFLICT (content): Merge conflict in foo.txt
$ git status
On branch master
Unmerged paths:
   (use "git reset HEAD <file>..." to unstage)
   (use "git add <file>..." to mark resolution)

both modified: foo.txt

=> The advices shown here are OK. Then:

$ git add foo.txt
$ git status
On branch master
Changes to be committed:
   (use "git reset HEAD <file>..." to unstage)
Quoted 4 lines

modified: foo.txt

=> here, "git status" could have hinted the user "you may now run 'git stash drop' if you are satisfied with your merge".

Though I don't know why you think this is important:

Quoted 3 lines

Now, the real question is: when would Git stop showing this advice. I don't see a real way to answer this, and I'd rather avoid doing just a guess.

If it is really annoying for the user, we can just have a configuration parameter to switch this message on/off. I don't know whether git has such customizations (in general) currently.

This is very useful (maybe we can agree on wording later):

Quoted 11 lines

One easy thing to do OTOH would be to show a hint at the end of "git stash pop"'s output, like

$ git stash pop
Auto-merging foo.txt
CONFLICT (content): Merge conflict in foo.txt
'stash pop' failed. Please resolve the conflicts manually. The stash
was not dropped in case you need to restart the operation. When you are
done resolving the merge, you may run the following to drop the stash reference:

git stash drop

#7 lore raw
Quoted 6 lines · Omar Othman

Though I don't know why you think this is important:

Quoted 3 lines

Now, the real question is: when would Git stop showing this advice. I don't see a real way to answer this, and I'd rather avoid doing just a guess.

If it is really annoying for the user, we can just have a configuration parameter to switch this message on/off.

Just saying "You have X stash" is OK to me as long as there is an option to deactivate it.

Hinting "You should now run "git stash drop"." OTOH is far more dangerous if guessed wrong. Keeping a stash active when you don't need it does no real harm, but droping one you actually needed is data loss.

Signature · 2 lines
Matthieu Moy
http://www-verimag.imag.fr/~moy/
#8 lore raw
Quoted 9 lines · Matthieu Moy
Quoted 6 lines · Omar Othman

Though I don't know why you think this is important:

Quoted 3 lines

Now, the real question is: when would Git stop showing this advice. I don't see a real way to answer this, and I'd rather avoid doing just a guess.

If it is really annoying for the user, we can just have a configuration parameter to switch this message on/off.

Quoted 6 lines

Just saying "You have X stash" is OK to me as long as there is an option to deactivate it.

Hinting "You should now run "git stash drop"." OTOH is far more dangerous if guessed wrong. Keeping a stash active when you don't need it does no real harm, but droping one you actually needed is data loss.

Yes, definitely.

I'm inclined to say that we should go in the direction you suggested earlier in Message-ID: <[email protected]>, that is:

Quoted 10 lines
Quoted 10 lines

One easy thing to do OTOH would be to show a hint at the end of "git stash pop"'s output, like

$ git stash pop
Auto-merging foo.txt
CONFLICT (content): Merge conflict in foo.txt
'stash pop' failed. Please, resolve the conflicts manually. The stash
was not dropped in case you need to restart the operation. When you are
done resolving the merge, you may run the following to drop the stash:
Quoted 3 lines
Quoted 3 lines

git stash drop

or so (I couldn't find a concise yet accurate wording).

I'd however have to say that even "please resolve the conflicts manually" is over-assuming.

I often start some WIP of a fix, realize that the fix should apply to a lot older maintenance branch than where I happened to have started the WIP (which typically is at the tip of somebody else's branch where I received the series from the list---and then noticed some existing breakage that needs to be fixed), stash the WIP, and then repeat:

(1) checkout an old maintenance track;
(2) try to pop;
(3) if it succeeds, stop the iteration;
(4) otherwise, reset and go back to (1) to checkout a bit newer maintenance track.

to decide. So "resolve the conflicts" is assuming the intention of the user who issued "pop" too much (let alone "manually"---it does not matter how the user resolves conflicts---the only thing we want to say is Git did all it would and no further automated help in resolving is availble, but "manually" is not quite the word).

"The stash was not dropped" is the most important thing in your additional text. How about rephrasing like this?

    $ git stash pop
    Auto-merging foo.txt
    CONFLICT (content): Merge conflict in foo.txt

The stashed change could not be replayed cleanly, leaving conflicts in the working tree. The stash was not dropped in case you need it again.

After you are done with the stash, you may want to "git stash drop" to discard it.

#9 lore raw
Quoted 2 lines · Junio C Hamano

I'd however have to say that even "please resolve the conflicts manually" is over-assuming.

I understand your point, but in a short hint message, I still find it reasonable. Fixing conflicts is the natural way to go after a "stash pop", and the user who do not want to go this way probably knows why.

Quoted 7 lines

"The stash was not dropped" is the most important thing in your additional text. How about rephrasing like this?

    $ git stash pop
    Auto-merging foo.txt
    CONFLICT (content): Merge conflict in foo.txt
Quoted 6 lines

The stashed change could not be replayed cleanly, leaving conflicts in the working tree. The stash was not dropped in case you need it again.

After you are done with the stash, you may want to "git stash drop" to discard it.

I'm fine with this, but it's even longer than mine which I already found too long. Perhaps the "leaving conflicts in the working tree" could be dropped, as the message follows "CONFLICT (content): Merge conflict in foo.txt".

Signature · 2 lines
Matthieu Moy
http://www-verimag.imag.fr/~moy/
#10 lore raw
Quoted 20 lines · Matthieu Moy
Quoted 2 lines · Junio C Hamano

I'd however have to say that even "please resolve the conflicts manually" is over-assuming.

I understand your point, but in a short hint message, I still find it reasonable. Fixing conflicts is the natural way to go after a "stash pop", and the user who do not want to go this way probably knows why.

Quoted 11 lines

"The stash was not dropped" is the most important thing in your additional text. How about rephrasing like this?

    $ git stash pop
    Auto-merging foo.txt
    CONFLICT (content): Merge conflict in foo.txt

The stashed change could not be replayed cleanly, leaving conflicts in the working tree. The stash was not dropped in case you need it again.

Quoted 7 lines
Quoted 2 lines

After you are done with the stash, you may want to "git stash drop" to discard it.

I'm fine with this, but it's even longer than mine which I already found too long. Perhaps the "leaving conflicts in the working tree" could be dropped, as the message follows "CONFLICT (content): Merge conflict in foo.txt".

All that verbosity...

$ git stash pop
Auto-merging foo.txt
CONFLICT (content): Merge conflict in foo.txt
Cowardly refusing to drop stash.
$
Signature · 1 line
David Kastrup
#11 lore raw
Quoted 7 lines · David Kastrup

All that verbosity...

$ git stash pop
Auto-merging foo.txt
CONFLICT (content): Merge conflict in foo.txt
Cowardly refusing to drop stash.
$

Actually, modulo "Cowardly", that may be the most harmless phrasing, as apply_stash may try to signal an error for reasons not related to an inability to apply the change cleanly (e.g. we may have failed to refresh the index).

Whatever phrasing we may end up choosing, the change itself should be trivial in any case.

 git-stash.sh | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
git-stash.sh +8 -2
index f0a94ab..4798bcf 100755
@@ -512,8 +512,14 @@ apply_stash () {
 pop_stash() {
 	assert_stash_ref "$@"
 
-	apply_stash "$@" &&
-	drop_stash "$@"
+	if apply_stash "$@"
+	then
+		drop_stash "$@"
+	else
+		status=$?
+		say "The stash is kept in case you need it again."
+		exit $status
+	fi
 }
 
 drop_stash () {
#13 lore raw
In reply to Matthieu Moy
Quoted 20 lines · Matthieu Moy
Quoted 2 lines · Junio C Hamano

I'd however have to say that even "please resolve the conflicts manually" is over-assuming.

I understand your point, but in a short hint message, I still find it reasonable. Fixing conflicts is the natural way to go after a "stash pop", and the user who do not want to go this way probably knows why.

Quoted 11 lines

"The stash was not dropped" is the most important thing in your additional text. How about rephrasing like this?

    $ git stash pop
    Auto-merging foo.txt
    CONFLICT (content): Merge conflict in foo.txt

The stashed change could not be replayed cleanly, leaving conflicts in the working tree. The stash was not dropped in case you need it again.

Quoted 7 lines
Quoted 2 lines

After you are done with the stash, you may want to "git stash drop" to discard it.

I'm fine with this, but it's even longer than mine which I already found too long. Perhaps the "leaving conflicts in the working tree" could be dropped, as the message follows "CONFLICT (content): Merge conflict in foo.txt".

Surely. s/was not dropped/is kept/ would make the result even shorter.

We can also remove the last three lines, for that matter.

#16 lore raw
In reply to Matthieu Moy
Quoted 10 lines · Matthieu Moy
Quoted 5 lines · Omar Othman

[omar_othman main (trunk|MERGING*)]$ git add path/to/file.txt [omar_othman main (trunk*)]$

Note how the status message has changed to show that git is now happy. It is at that moment that the stash reference should be dropped

Dropping the stash on a "git add" operation would be really, really weird...

Why? That is when the merge conflicts are resolved, which is what logically indicates that the stash is no longer needed, _if_ the merge conflicts are related to the stash, which is true in this use case.

There are other uses for 'git add' that don't indicate that; we'd have to be very careful to not throw away the stash at the wrong time.

Quoted 4 lines
Quoted 2 lines

(or the user (somehow) is notified to do that herself if desired), because this means that the popping operation has succeeded.

But how would you expect to "be notified"?

When 'git add' checks to see if all merge conflicts are now resolved, and those merge conflicts were related to the stash, it can either pop the stash, or issue a message telling the user it is now safe to do so. We would need a config setting to indicate which to do.

Maybe that check is hard to do in general?

Signature · 1 line
-- Stephe
#17 lore raw
Quoted 5 lines · Stephen Leake
Quoted 2 lines

Dropping the stash on a "git add" operation would be really, really weird...

Why? That is when the merge conflicts are resolved, which is what logically indicates that the stash is no longer needed,...

Not necessarily. Imagine a case where you used stash to quickly save away a tangled mess that was not ready for a logically single commit and now you are in the process of creating the first commit by applying it piece-by-piece to create multiple resulting ones. After you commit the result, you would still want to keep the parts of that stashed change you did not include in the first commit so that you can go back, no?

You may run "git add", but that does not say anything about what you are going to use the rest of the stash for. Not even "git commit" may be a good enough sign.

#18 lore raw
Quoted 16 lines · Junio C Hamano
Quoted 5 lines · Stephen Leake
Quoted 2 lines

Dropping the stash on a "git add" operation would be really, really weird...

Why? That is when the merge conflicts are resolved, which is what logically indicates that the stash is no longer needed,...

Not necessarily. Imagine a case where you used stash to quickly save away a tangled mess that was not ready for a logically single commit and now you are in the process of creating the first commit by applying it piece-by-piece to create multiple resulting ones. After you commit the result, you would still want to keep the parts of that stashed change you did not include in the first commit so that you can go back, no?

Quoted 3 lines

You may run "git add", but that does not say anything about what you are going to use the rest of the stash for. Not even "git commit" may be a good enough sign.

But we are only talking about the situation where you typed "git stash pop", and this resulted in a merge conflict. Your intention was clearly to drop the stash, it just wasn't dropped because of the conflict. Dropping it automatically once the conflict is resolved would be nice.

I know it happened to me too that I forgot to drop a stash after resolving conflicts, so I'd appreciate a feature that somehow does this automatically for me.

Signature · 3 lines
Stefan Haller
Berlin, Germany
http://www.haller-berlin.de/
#19 lore raw
Quoted 3 lines · [email protected] (Stefan Haller) writes:

Your intention was clearly to drop the stash, it just wasn't dropped because of the conflict. Dropping it automatically once the conflict is resolved would be nice.

Your intention when you ran "git stash pop", yes. Your intention when you ran "git add", I call that guessing.

The condition for dropping the stash should be more "conflits resolutions are done AND the user is happy with it". Otherwise, if you mess up your conflict resolution, and notice it after running "git add", then you're screwed because Git just happily discarded your important data. The point of keeping the stash is to leave it up to the user to decide between "I'm happy, I can drop" or "I'm not, I should re-apply", and Git cannot tell which is which.

Hinting the user to run "stash pop" would be more acceptable, but talking about "git stash" in "git add"'s code is somehow a dependency order violation (stash is normally implemented on top of Git's basic features, not the other way around). Does not seem serious from at first from the user point of view, but this pushes the codebase one step in the direction of an unmaintainable mess.

Signature · 2 lines
Matthieu Moy
http://www-verimag.imag.fr/~moy/
#37 lore raw
In reply to Junio C Hamano
Quoted 3 lines · Junio C Hamano

So, I tend to agree with you, while I do understand where "I want to know about what is in stash" is coming from (and that is why we do have "git stash list" command).

One thing that would be nice is if there was built-in "git stash list" option which only shows the stash items which match the current branch. The discussion on this thread inspired me to create the following:

#!/bin/sh

b=$(git symbolic-ref HEAD | sed -e 's;refs/heads/;;')

git stash list --pretty="%gd %cr on: %s" | grep "WIP on $b" | \
    sed -e "s/ WIP on $b: [0-9a-f]*//"

This results in:

stash@{0} 4 weeks ago on: mke2fs: add make_hugefile feature
stash@{1} 5 weeks ago on: e2fsck, mke2fs: enable octal integers in the profile/config file stash@{2} 5 weeks ago on: e2fsck, mke2fs: enable octal integers in the profile/config file stash@{3} 5 weeks ago on: mke2fs: optimize fix_cluster_bg_counts()
stash@{4} 8 weeks ago on: e4defrag: choose the best available posix_fadvise variant stash@{5} 9 weeks ago on: e2image: add -c option to optimize file system copying for flash devices stash@{6} 9 weeks ago on: e2image: clean up gcc -Wall and sparse nits
stash@{7} 9 weeks ago on: e2fsck: fix printf conversion specs in ea_refcount.c

(Yes, I have a lot of junk on my git stash; showing the relative time is going to help my GC what I have left on my git stash list.)

Cheers,

- Ted

#38 lore raw
In reply to Junio C Hamano
Quoted 34 lines
Quoted 10 lines · Matthieu Moy
Quoted 8 lines · Holger Hellmuth

Am 24.02.2014 17:21, schrieb Matthieu Moy:

Quoted 7 lines
$ git add foo.txt
$ git status
On branch master
Changes to be committed:
    (use "git reset HEAD <file>..." to unstage)

modified: foo.txt

Quoted 8 lines
Quoted 2 lines

Maybe status should display a stash count if that count is > 0, as this is part of the state of the repo.

Maybe it would help some users, but not me for example. My main use of "git stash" is a safe replacement for "git reset --hard": when I want to discard changes, but keep them safe just in case.

So, my stash count is almost always >0, and I don't want to hear about it.

"status" is about reminding the user what changes are already in the index (i.e. what you would commit) and what changes are in the working tree, from which you could further update the index with (i.e. what you could commit).

One _could_ argue that stashed changes are what could be reflected to the working tree and form the source of the latter, but my gut feeling is that it is a rather weak argument. At that point you are talking about what you could potentially change in the working tree, and the way to do so is not limited to "stash pop" (i.e. you can "git cherry-pick --no-commit $a_commit", or "edit" any file in the working tree for that matter, with the same ease).

Quoted 3 lines

So, I tend to agree with you, while I do understand where "I want to know about what is in stash" is coming from (and that is why we do have "git stash list" command).

Same comment. Everyone will have his own opinion. As long as the messages are not customizable, we can debate for hours and everybody has a valid point.

#39 lore raw
In reply to Junio C Hamano
Quoted 4 lines · Junio C Hamano

"status" is about reminding the user what changes are already in the index (i.e. what you would commit) and what changes are in the working tree, from which you could further update the index with (i.e. what you could commit).

I believe "status" should tell me everything git knows about the current workspace in a resonably concise way. That includes the stash.

Quoted 4 lines

One _could_ argue that stashed changes are what could be reflected to the working tree and form the source of the latter, but my gut feeling is that it is a rather weak argument. At that point you are talking about what you could potentially change in the working tree,

No, I saved things in the stash on purpose. For example, I had changes that were not ready to commit, but I wanted to do a merge from upstream.

There are workflows where the stash is not important; provide an option to 'git status' that means "ignore stash".

Quoted 3 lines

So, I tend to agree with you, while I do understand where "I want to know about what is in stash" is coming from (and that is why we do have "git stash list" command).

My Emacs front end currently checks both 'git status' and 'git stash list' to build "the status of the current workspace".

Signature · 1 line
-- Stephe
#40 lore raw
Quoted 7 lines · Stephen Leake
Quoted 4 lines

One _could_ argue that stashed changes are what could be reflected to the working tree and form the source of the latter, but my gut feeling is that it is a rather weak argument. At that point you are talking about what you could potentially change in the working tree,

No, I saved things in the stash on purpose. For example, I had changes that were not ready to commit, but I wanted to do a merge from upstream.

I often save things by running "git diff >P.diff" on purpose. Should "git status" read these patches and tell me what paths I could change in the working tree by applying it? Where does it end?

Quoted 2 lines

There are workflows where the stash is not important; provide an option to 'git status' that means "ignore stash".

How is that different to tell those who want to know what are in the stash to type "git stash list" when they want to learn that information?

#42 lore raw
In reply to Matthieu Moy
Quoted 10 lines · Matthieu Moy
Quoted 2 lines · Holger Hellmuth

Maybe status should display a stash count if that count is > 0, as this is part of the state of the repo.

Maybe it would help some users, but not me for example. My main use of "git stash" is a safe replacement for "git reset --hard": when I want to discard changes, but keep them safe just in case.

So, my stash count is almost always >0, and I don't want to hear about it.

I concur with this. Sometimes the stashed changes are remnants of a small hack or a very brief start to an aborted project that I stashed when I needed to change branches. I figure that they might be useful in the future, but I don't care about them right now. I may pick them up, I may not, but I certainly don't want to be reminded of them constantly.

Signature · 3 lines
brian m. carlson / brian with sandals: Houston, Texas, US
+1 832 623 2791 | http://www.crustytoothpaste.net/~bmc | My opinion only
OpenPGP: RSA v4 4096b: 88AC E9B2 9196 305B A994 7552 F1BA 225C 0223 B187
#43 lore raw
In reply to Holger Hellmuth
Quoted 18 lines

Am 24.02.2014 17:21, schrieb Matthieu Moy:

Quoted 7 lines
$ git add foo.txt
$ git status
On branch master
Changes to be committed:
   (use "git reset HEAD <file>..." to unstage)

modified: foo.txt

Maybe status should display a stash count if that count is > 0, as this is part of the state of the repo.

$ git status
On branch master
Stashes: 1                         <----------
Changes to be committed:
    (use "git reset HEAD <file>..." to unstage)
Quoted 3 lines

modified: foo.txt

It would be in Omars example case a clear message that git kept the stash. And generally a reminder that there is still a stash around that might or might not be obsolete.

Again, the same comment: If there is a way to customize git's messages by turning them on/off (or, even cooler, the ability to change their wording) then this is also a nice option to have and we can turn it off by default if we find that most people (here at least) don't like it. I don't know whether you guys have discussed this option before (or does it exist? I doubt, but I don't know), because having such an option (the ability to turn messages on/off or change their wording and what internal status information they manifest) will really resolve all kinds of such potential conflicts of preferences. Even cooler, people will be able to change the wording to their native languages for example.

#44 lore raw
In reply to Matthieu Moy
Quoted 2 lines · Matthieu Moy

One easy thing to do OTOH would be to show a hint at the end of "git stash pop"'s output, like

I think that's a good idea. It makes it obvious that Git has kept the stash and that the user should drop it when he's done - if he wants to.

Quoted 8 lines
$ git stash pop
Auto-merging foo.txt
CONFLICT (content): Merge conflict in foo.txt
'stash pop' failed. Please, resolve the conflicts manually. The stash
was not dropped in case you need to restart the operation. When you are
done resolving the merge, you may run the following to drop the stash:

git stash drop

Maybe just the following to keep the output on a single line:

Use 'git stash drop' to remove the stash after resolving the conflicts.

But maybe that's too short as it doesn't mention explicitly, that the stash was kept.

Regards
Simon

Signature · 3 lines
+ privacy is necessary
+ using gnupg http://gnupg.org
+ public key id: 0x92FEFDB7E44C32F9
#12 lore raw
In reply to Junio C Hamano
Quoted 10 lines · Junio C Hamano
Quoted 7 lines · David Kastrup

All that verbosity...

$ git stash pop
Auto-merging foo.txt
CONFLICT (content): Merge conflict in foo.txt
Cowardly refusing to drop stash
$
Quoted 4 lines

Actually, modulo "Cowardly", that may be the most harmless phrasing, as apply_stash may try to signal an error for reasons not related to an inability to apply the change cleanly (e.g. we may have failed to refresh the index).

Without "Cowardly", the capriciosity of "refusing" does not make much sense. The error message is a tribute to GNU tar:

dak@lola:/tmp$ mkdir x
dak@lola:/tmp$ tar cfz x
tar: Cowardly refusing to create an empty archive
Try `tar --help' or `tar --usage' for more information.
dak@lola:/tmp$ 

The boring variant would be

$ git stash pop
Auto-merging foo.txt
CONFLICT (content): Merge conflict in foo.txt
Not dropping stash
$
Signature · 1 line
David Kastrup
#15 lore raw
In reply to Matthieu Moy
Quoted 11 lines · Matthieu Moy
Quoted 6 lines · Omar Othman

Though I don't know why you think this is important:

Quoted 3 lines

Now, the real question is: when would Git stop showing this advice. I don't see a real way to answer this, and I'd rather avoid doing just a guess.

If it is really annoying for the user, we can just have a configuration parameter to switch this message on/off.

Just saying "You have X stash" is OK to me as long as there is an option to deactivate it.

+1

Quoted 3 lines

Hinting "You should now run "git stash drop"." OTOH is far more dangerous if guessed wrong. Keeping a stash active when you don't need it does no real harm, but droping one you actually needed is data loss.

I agree giving possibly incorrect advice is bad.

Can you construct a use case where git will give incorrect advice?

I don't know git well enough to do that, nor to assert that it will never happen.

I think we need a more concrete proposal to move this forward.

Signature · 1 line
-- Stephe
#41 lore raw
In reply to Junio C Hamano
Quoted 11 lines · Junio C Hamano
Quoted 7 lines · Stephen Leake
Quoted 4 lines

One _could_ argue that stashed changes are what could be reflected to the working tree and form the source of the latter, but my gut feeling is that it is a rather weak argument. At that point you are talking about what you could potentially change in the working tree,

No, I saved things in the stash on purpose. For example, I had changes that were not ready to commit, but I wanted to do a merge from upstream.

I often save things by running "git diff >P.diff" on purpose.

Ok. How is that better than 'git stash save'?

Quoted 2 lines

Should "git status" read these patches and tell me what paths I could change in the working tree by applying it?

No, 'git stash save' appears to be the method git provides to do this, so it is the only one that git needs to support.

(The content of 'P.diff' already tells you what paths are modified, as does 'git stash show')

But I am new to git, so I could just be missing the point.

Quoted 1 line

Where does it end?

Where we agree it ends :).

Quoted 6 lines
Quoted 2 lines

There are workflows where the stash is not important; provide an option to 'git status' that means "ignore stash".

How is that different to tell those who want to know what are in the stash to type "git stash list" when they want to learn that information?

You are correct, this is a question of style. The question is:

Which style is best for git, considering the needs of newbies and seasoned users?

As a newbie, I find these things confusing:

- the stash status is not displayed by 'git status'

- 'git add' does not report that all pending merge conflicts are now resolved.

I'm sure I will discover other confusing things in the future :).

I am a seasoned user of CM systems in general; in all cases, I have customized an Emacs front-end to do _exactly_ what I want, rather than relying on the command line tools directly. So I have a rather extreme perspective on this :). I do rely on the command line tools while learning a new CM system.

In general, I expect seasoned users to be more accepting of the need to provide additional options to customize the tools to their workflow.

Signature · 1 line
-- Stephe
#45 lore raw
In reply to Simon Ruderich
Quoted 7 lines · Simon Ruderich
Quoted 2 lines · Matthieu Moy

One easy thing to do OTOH would be to show a hint at the end of "git stash pop"'s output, like

I think that's a good idea. It makes it obvious that Git has kept the stash and that the user should drop it when he's done - if he wants to.

+1

This does not mean I don't _also_ think 'git add' dropping the stash when the last conflict is resolved is a good idea. If that is implemented, 'stash pop' might have to mention that effect as well; that does make things more complicated.

Signature · 1 line
-- Stephe
#14 lore raw
In reply to Junio C Hamano
Quoted 5 lines · Junio C Hamano

... So "resolve the conflicts" is assuming the intention of the user who issued "pop" too much (let alone "manually"---it does not matter how the user resolves conflicts---the only thing we want to say is Git did all it would and no further automated help in resolving is availble, but "manually" is not quite the word).

+1

Quoted 7 lines

"The stash was not dropped" is the most important thing in your additional text. How about rephrasing like this?

    $ git stash pop
    Auto-merging foo.txt
    CONFLICT (content): Merge conflict in foo.txt
Quoted 6 lines

The stashed change could not be replayed cleanly, leaving conflicts in the working tree. The stash was not dropped in case you need it again.

After you are done with the stash, you may want to "git stash drop" to discard it.

+1

Signature · 1 line
-- Stephe
#20 lore raw
In reply to Matthieu Moy
Quoted 8 lines · Matthieu Moy
Quoted 3 lines · [email protected] (Stefan Haller) writes:

Your intention was clearly to drop the stash, it just wasn't dropped because of the conflict. Dropping it automatically once the conflict is resolved would be nice.

Your intention when you ran "git stash pop", yes. Your intention when you ran "git add", I call that guessing.

You might be adding other files for other reasons. But if you add a file that does resolve a conflict caused by 'git stash pop', it is not guessing.

Quoted 7 lines

The condition for dropping the stash should be more "conflits resolutions are done AND the user is happy with it". Otherwise, if you mess up your conflict resolution, and notice it after running "git add", then you're screwed because Git just happily discarded your important data. The point of keeping the stash is to leave it up to the user to decide between "I'm happy, I can drop" or "I'm not, I should re-apply", and Git cannot tell which is which.

Yes, that makes sense.

Quoted 6 lines

Hinting the user to run "stash pop" would be more acceptable, but talking about "git stash" in "git add"'s code is somehow a dependency order violation (stash is normally implemented on top of Git's basic features, not the other way around). Does not seem serious from at first from the user point of view, but this pushes the codebase one step in the direction of an unmaintainable mess.

Also makes sense.

So "git add" and "git stash *" are lower level tools; to get the effect we are asking for, we should use a front-end (which is why I'm writing one for Emacs :).

Signature · 1 line
-- Stephe
#21 lore raw

Stephan:

Quoted 3 lines · Stephen Leake

You might be adding other files for other reasons. But if you add a file that does resolve a conflict caused by 'git stash pop', it is not guessing.

Staging a file doesn't tell git that you resolved a conflict. Git will happily accept a blob full of conflict markers. Git doesn't know the difference. Git expects the user to know what is right. The user has the freedom to manipulate the index as they see fit, which means both adding and removing from it anytime they wish.

Quoted 3 lines

So "git add" and "git stash *" are lower level tools; to get the effect we are asking for, we should use a front-end (which is why I'm writing one for Emacs :).

You *can* use a front end, but I would argue that you shouldn't necessarily. Most third-party front ends only serve to confuse users. In general, they only cause problems and encourage ignorance.

Git is a very pure system. It doesn't impose too may rules on you. It basically just gives you the tools that you need to work within the system and gets out of your way. It is up to the user to learn how to assemble those tools for good (and many front ends exist to help; sometimes arguably too many as it is, such as git-pull(1) for example).

This isn't a case of the API being wrong. This is a case of PEBKAC,
IMO. Maybe the API can be a little bit more verbose in assisting the user to understand what has happened and what sensible options there are, but we should avoid catering to newbies too much. You should only be a newbie for a short time. After that you should begin to learn the API. Hand holding at that point would be noise (as it would for most of us here, I imagine). The worst kind of "hand holding" is the kind that imposes rules on you that aren't universal. Dropping the stash after adding all changes to the index after a failed pop is not universal. At most, git stash pop should give the user a bit more guidance to understand what the situation is. At least, the user should RTFM and learn to use the tools. And that might involve some mistakes, but you learn from mistakes. At least Git does a good job of making it easy to recover from most of your mistakes. The proposed change to git-add takes away one of those safety nets.

Git isn't always the easiest thing to wrap your head around, but I have found that once you have wrapped your head around it Git is the easiest thing to get the job done the way you want. I consider the learning curve a strength of Git. Which isn't to say that there isn't room for improvement, but when proposing improvements we should try to make sure that they actually make things universally better.

Regards,

Signature · 6 lines
Brandon McCaig <[email protected]> <[email protected]>
Castopulence Software <https://www.castopulence.org/>
Blog <http://www.bamccaig.com/>
perl -E '$_=q{V zrna gur orfg jvgu jung V fnl. }.
q{Vg qbrfa'\''g nyjnlf fbhaq gung jnl.};
tr/A-Ma-mN-Zn-z/N-Zn-zA-Ma-m/;say'
#22 lore raw
Quoted 11 lines · Brandon McCaig
Quoted 3 lines · Stephen Leake

You might be adding other files for other reasons. But if you add a file that does resolve a conflict caused by 'git stash pop', it is not guessing.

Staging a file doesn't tell git that you resolved a conflict. Git will happily accept a blob full of conflict markers. Git doesn't know the difference. Git expects the user to know what is right. The user has the freedom to manipulate the index as they see fit, which means both adding and removing from it anytime they wish.

But git has a notion of "unresolved conflict". For example, when I have conflicts from a 'git stash pop', 'git status' shows:

stephe@takver$ git status
# On branch master
# Unmerged paths:
#   (use "git reset HEAD <file>..." to unstage)
#   (use "git add/rm <file>..." as appropriate to mark resolution)
#
#	both modified:      CommandBasedAutonomous.java
#	both modified:      DriveByInches.java
#
# ...

How does it know those files are "unmerged"? I'm guessing it has recorded the fact that they had conflicts. Where does it record that?

In fact, at this point, I have edited CommandBasedAutonomous.java to resolve the conflicts. But git apparently doesn't know that.

So I do 'git add CommandBasedAutonomous.java', then 'git status':

stephe@takver$ git status
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#	modified:   AerialAssist2014/src/org/usfirst/frc1939/AerialAssist2014/commands/CommandBasedAutonomous.java
#
# Unmerged paths:
#   (use "git reset HEAD <file>..." to unstage)
#   (use "git add/rm <file>..." as appropriate to mark resolution)
#
#	both modified:      AerialAssist2014/src/org/usfirst/frc1939/AerialAssist2014/commands/DriveByInches.java

And git thinks that file is now "merged".

So it appears that adding a file _does_ tell git that the conflict is resolved.

Or am I still missing something?

Quoted 7 lines
Quoted 3 lines

So "git add" and "git stash *" are lower level tools; to get the effect we are asking for, we should use a front-end (which is why I'm writing one for Emacs :).

You *can* use a front end, but I would argue that you shouldn't necessarily. Most third-party front ends only serve to confuse users. In general, they only cause problems and encourage ignorance.

Won't happen here; I'm writing it. It may confuse other people, but not me :).

Quoted 1 line

Git is a very pure system.

Hmm. We'll have to disagree on that. git gives the impression of having grown organically for quite a while, and therefore suffers from changing and competing design paradigms and conflicting requirements due to preserving backward compatiblity.

monotone is much cleaner, since it has had very few design paradigm changes, and they were implemented cleanly, without preserving backward compatibility. monotone is not as flexible as git, but what I've seen so far could be added to monotone (I don't think it ever will be; monotone is dying as a project).

We are probably using different definitions of "pure" here.

Quoted 3 lines

It is up to the user to learn how to assemble those tools for good (and many front ends exist to help; sometimes arguably too many as it is, such as git-pull(1) for example).

Yes. Which is why we are discussing how much help git should be while still learning the rules.

Quoted 2 lines

This isn't a case of the API being wrong. This is a case of PEBKAC,
IMO.

(wikipedia to the rescue; PEBKAC = "operator error")

Yes, I'm not using it correctly, because I don't understand it yet. That's the definition of "newbie".

Quoted 2 lines

Dropping the stash after adding all changes to the index after a failed pop is not universal.

Not universal, but it appears to be very common; it is certainly what I expect, as a newbie. So it could be the default as long as there is a configuration option to have it not do that.

I _did_ "RTFM" (specifically the man page on 'git stash', and before that the git book at http://git-scm.com/documentation (which did not mention stash)); it did not explain the full cycle of how to resolve conflicts after stash pop.

Perhaps there is a different manual that I could read instead?

In particular, one that explains what "unmerged paths" means in the 'git status' output? The 'git-status' man page does not do that.

--
-- Stephe

#23 lore raw
Quoted 8 lines · Stephen Leake
Quoted 6 lines · Brandon McCaig
Quoted 3 lines · Stephen Leake

You might be adding other files for other reasons. But if you add a file that does resolve a conflict caused by 'git stash pop', it is not guessing.

Quoted 7 lines
Quoted 5 lines

Staging a file doesn't tell git that you resolved a conflict. Git will happily accept a blob full of conflict markers. Git doesn't know the difference. Git expects the user to know what is right. The user has the freedom to manipulate the index as they see fit, which means both adding and removing from it anytime they wish.

But git has a notion of "unresolved conflict".

Not really. It has a notion of "unmerged path".

Quoted 14 lines

For example, when I have conflicts from a 'git stash pop', 'git status' shows:

stephe@takver$ git status
# On branch master
# Unmerged paths:
#   (use "git reset HEAD <file>..." to unstage)
#   (use "git add/rm <file>..." as appropriate to mark resolution)
#
#	both modified:      CommandBasedAutonomous.java
#	both modified:      DriveByInches.java
#
# ...
Quoted 2 lines

How does it know those files are "unmerged"? I'm guessing it has recorded the fact that they had conflicts. Where does it record that?

The index contains the unmerged versions of the file. Possibly also the version with conflict markers, but it's been too long since I last checked.

After "git add", there is only one version in the index.

If you apply a stash with unmerged paths to a worktree/index, possibly containing unmerged paths of its own, possibly getting new unmerged paths by failing to apply the stash, you get unmerged paths from several different unresolved conflicts.

Git has no idea about the history of unmerged paths. So having "git add" modify the operation of "git reset" whenever "git add" overwrites an unmerged path in the index could lead to quite funny results.

Signature · 1 line
David Kastrup
#24 lore raw
Quoted 18 lines · David Kastrup
Quoted 8 lines · Stephen Leake
Quoted 6 lines · Brandon McCaig
Quoted 3 lines · Stephen Leake

You might be adding other files for other reasons. But if you add a file that does resolve a conflict caused by 'git stash pop', it is not guessing.

Quoted 7 lines
Quoted 5 lines

Staging a file doesn't tell git that you resolved a conflict. Git will happily accept a blob full of conflict markers. Git doesn't know the difference. Git expects the user to know what is right. The user has the freedom to manipulate the index as they see fit, which means both adding and removing from it anytime they wish.

But git has a notion of "unresolved conflict".

Quoted 7 lines

Not really. It has a notion of "unmerged path".

<snip>

The index contains the unmerged versions of the file. Possibly also the version with conflict markers, but it's been too long since I last checked.

Paraphrasing, is this correct?

"the index contains both versions of the unmerged file; any file
with more than one version in the index is unmerged".

So what 'git add' does in this case is replace both versions of the file in the index with a new version.

I was not aware that the git system could support more than one version of a file in one branch. That makes it more like monotone :).

Quoted 4 lines

If you apply a stash with unmerged paths to a worktree/index, possibly containing unmerged paths of its own, possibly getting new unmerged paths by failing to apply the stash, you get unmerged paths from several different unresolved conflicts.

Yes; doing too many things at once is a bad idea. But that should never cause git to lose data or do something wrong.

At the same time, it seems all unmerged paths result from unresolved merge conflicts, so the two notions are equivalent for git?

Quoted 3 lines

Git has no idea about the history of unmerged paths. So having "git add" modify the operation of "git reset" whenever "git add" overwrites an unmerged path in the index could lead to quite funny results.

Ok; I'll take that as describing a large class of "bad thing" use cases.

Signature · 1 line
-- Stephe
#25 lore raw
Quoted 2 lines · Stephen Leake

I was not aware that the git system could support more than one version of a file in one branch.

The index only. The history itself does not.

Signature · 2 lines
Matthieu Moy
http://www-verimag.imag.fr/~moy/
#26 lore raw
In reply to Stephen Leake
Quoted 2 lines · Stephen Leake

So it appears that adding a file _does_ tell git that the conflict is resolved.

Yes it does. Git _knows_ that you consider the conflict to be resolved. It cannot know how happy you are with the result.

Similarly, in a conflicted merge, the last "git add" does not trigger a commit silently. And a silent commit would be much less serious than a silent data drop.

Signature · 2 lines
Matthieu Moy
http://www-verimag.imag.fr/~moy/
#27 lore raw
Quoted 11 lines · Matthieu Moy
Quoted 2 lines · Stephen Leake

So it appears that adding a file _does_ tell git that the conflict is resolved.

Yes it does. Git _knows_ that you consider the conflict to be resolved. It cannot know how happy you are with the result.

Similarly, in a conflicted merge, the last "git add" does not trigger a commit silently. And a silent commit would be much less serious than a silent data drop.

Ok, I see your point now.

So a message "merge complete; you can drop the stash" would be the most git should do.

Signature · 1 line
-- Stephe
#28 lore raw
Quoted 4 lines · Stephen Leake

So a message "merge complete; you can drop the stash" would be the most git should do.

From the user experience point of view, that would be good. It could

bother some users, but we have advice.* to silent this kind of warnings.

Quoted 1 line

From the implementation point of view, it's much harder than it seems

because as other pointed out, Git does not know that the merge conflicts comes from, so as it is, the best it could say is "merge complete; you can now proceed". Thas is a solvable problem (git stash could leave a file like .git/conflicted-stash, and git add could look for this file and remove it), but I can't think of an implementation that would not be really awful. For example, "git reset" should also remove the file, and in general a substancial subset of Git's command would need to be aware of the status of git stash.

So, I wouldn't object, but I don't think the implementation cost is worth the benefit.

Signature · 2 lines
Matthieu Moy
http://www-verimag.imag.fr/~moy/
#30 lore raw
In reply to Stephen Leake
Quoted 8 lines · Stephen Leake
Quoted 6 lines · Matthieu Moy
Quoted 3 lines · [email protected] (Stefan Haller) writes:

Your intention was clearly to drop the stash, it just wasn't dropped because of the conflict. Dropping it automatically once the conflict is resolved would be nice.

Quoted 6 lines
Quoted 2 lines

Your intention when you ran "git stash pop", yes. Your intention when you ran "git add", I call that guessing.

You might be adding other files for other reasons. But if you add a file that does resolve a conflict caused by 'git stash pop', it is not guessing.

The only thing you know for sure is that the user has consumed _one_ part of the stashed change, no? What if the stash had changes for more than one path?

At the time of "git add $path", can you reliably tell if the conflict to the $path the user is resolving came from a previous "git stash pop", not from any other mergy operations, e.g. "git stash apply" or "git apply -3"?

#29 lore raw
In reply to Matthieu Moy
Quoted 5 lines · Matthieu Moy
Quoted 2 lines · Stephen Leake

So a message "merge complete; you can drop the stash" would be the most git should do.

Quoted 7 lines

From the user experience point of view, that would be good. It could bother some users, but we have advice.* to silent this kind of warnings.

<snip explanation of implementation issues>

So, I wouldn't object, but I don't think the implementation cost is worth the benefit.

Ok, that makes sense.

Signature · 1 line
-- Stephe
#31 lore raw
In reply to Junio C Hamano
Quoted 13 lines · Junio C Hamano
Quoted 11 lines · Stephen Leake
Quoted 8 lines · Matthieu Moy
Quoted 3 lines · [email protected] (Stefan Haller) writes:

Your intention was clearly to drop the stash, it just wasn't dropped because of the conflict. Dropping it automatically once the conflict is resolved would be nice.

Your intention when you ran "git stash pop", yes. Your intention when you ran "git add", I call that guessing.

Quoted 7 lines
Quoted 3 lines

You might be adding other files for other reasons. But if you add a file that does resolve a conflict caused by 'git stash pop', it is not guessing.

The only thing you know for sure is that the user has consumed _one_ part of the stashed change, no? What if the stash had changes for more than one path?

Count the unmerged paths in the index; when the count is zero, all conflicts are resolved.

paths in the stash that had no conflicts are already in the index.

So _if_ there is nothing going on except finishing the stash pop, an unmerged path count of zero means you are done with the stash, and it can be dropped.

Quoted 4 lines

At the time of "git add $path", can you reliably tell if the conflict to the $path the user is resolving came from a previous "git stash pop", not from any other mergy operations, e.g. "git stash apply" or "git apply -3"?

This is the real problem. I can impose a rule on my team of "don't do more than one merge at a time" by implementing that in the front-end, but git can't assume that.

Signature · 1 line
-- Stephe