Re: A bug or issue with "git rebase --autostash" not popping the stash automatically

2 messages, 2 authors, 2021-12-14 · open the first message on its own page

Re: A bug or issue with "git rebase --autostash" not popping the stash automatically

From: Philippe Blain <hidden>
Date: 2021-12-13 13:46:25

Hi Henk,

Le 2021-11-15 à 05:19, Henk Smit a écrit :
Hello Philip,

May I ask you a question?
You may, but I might not answer, or even receive your email. It is always
a better idea to write to the mailing list, and CC people that you want to
be made aware of your message :)
Today I saw your post on the git mailing-list:
https://public-inbox.org/git/a0071549-73f6-9636-9279-3f01143a05de@gmail.com/
Regression in 'git pull --rebase --autostash' since v2.32.0

I am far from a git expert.
But I have seen the following behaviour (git version 2.26.2.dirty and git version 2.33.0)
1) I have a few changed files in my workspace
2) I want to "update" my workspace
3) the remote repository has one or more changes in files that I have altered too
4) I do a "git pull --rebase --autostash" or "git fetch && git rebase --autostash", etc
5) The fetch works. Autostash creates a stash. Remote changes are applied with the rebase.
6) PROBLEM: the stash is not automatically popped.

"git rebase" complains that there are conflicts (can't remember the exact wording).
This happens when there are real conflicts (local and remote changes in the same line(s)).
But also when the changes are at different locations inside the files. Not real conflicts, imho.
"git rebase" says "Your changes are safe in the stash". It doesn't pop and apply them.
Yes, that's the correct behaviour. If there are conflicts in the rebase, we do not apply the stash,
since it could make the situation even worse if the modifications in the stash also conflict with
the same lines as the rebase conflict. That fact, I realize, is missing from the documentation [1].
When I then type "git stash pop" manually, the stash pops, changes are edited in, with the
usual ">>>" and "<<<" markers. Everything is fine. Except that the stash is still there
and I have to delete it manually.
So, the stash does not apply automatically, there are conflicts. As noted in [2], this is
the correct behaviour for 'git stash drop' [2].
My question: is this how it should work?
Imho, there is no reason to not always just pop the stash. Why do I have to pop (and delete
later) the stash manually? Is this a bug? Is there a way to make it happen automatically?
What you describe is working as it should,  I think.
Is this related to the issue you point out on the git mailing-list?
No, I was describing a case where the stash should have been applied automatically,
but it was not. This bug was fixed in Git 2.33.0 [3].
Would the current behaviour change in the latest version of git?
I don't think so, as from what I understand of the behaviour you are describing
and my reading of the docs, everything is working as it should.
Thanks,
henk.


Some background.
In a previous job, I worked 3 years with git. At that company, we used the "git up" plugin.
Programmers did 3 only 3 things: 1) clone a tree, 1a) edit, compile, test, repeat, 2) some
times update your workspace, 3) push your changes to the remote repository.
Step 2 was simple. Type "git up" and everything worked automatically.
A very very simple work-flow. But it was all we (the regular programmers) needed.

I now work for another company. A larger company. They've started using git earier this year.
Most people still use ACME (the previous source-code control system). They just clone a new
workspace right before pushing (creating a pull-request). So most programmers never update
their git workspaces. I am new, I skipped ACME, and use git only.

I used "git pull" to update my workspace. That failed sometimes, when/because I had changed
files that were also changed in the updates I tried to pull in. So I asked "how do I update
my workspace" to our git experts. Answer: "commit first". I don't want to commit. I don't want
my local changes split over multiple commits, etc. Basically they want everyone to become a
git-expert, before they can even use git. I think that is wrong. I think we should have a simple
work-flow for the average regular programmer.

So I've been looking to make updating just as easy as at my previous company. The "git up"
plugin is discontinued. Because "git pull --rebase --autostash" is supposed to do the same thing.
It almost does. But the autostash doesn't pop. You might forget and lose your stash, you might
forget deleting the stash after applying it once. It just makes updating your workspace a little
trickier than it should.
As I wrote above, the behaviour you are seeing is not a bug. When applying the stash would fail
due to conflicts, Git tells you about it:

         Applying autostash resulted in conflicts.
         Your changes are safe in the stash.
         You can run "git stash pop" or "git stash drop" at any time.

So it's up to you to remember to do it :)
If you want to have an "always-on" reminder that you have something stashed, you could use
'git-prompt.sh' [4], and set GIT_PS1_SHOWSTASHSTATE in your shell environment [5].
I asked our IT support, I asked our local git-expert, I asked our local GitHub support team.
I asked on stack-overflow. Nobody seems to know what proper behaviour should be. Most git-experts
don't seem to care. "Do what I do, which is do these 6 git commands, and then do these 3 other
git commands if you want to look at your diffs, and do these 7 git commands before you want
to push". I just want a simple way to update my workspace. One command, no surprises, nothing
extra needed. Am I crazy for wanting that?


So my question again: "is git rebase --autostash" supposed to always pop the stash or not?
If it is, is the current git behaviour a bug?
It's not, not when the rebase has conflicts, or when applying the stash results in conflicts.
Thanks again, thanks for your time,
henk.
Hope this helps,

Philippe.


[1] https://git-scm.com/docs/git-pull/2.34.0#Documentation/git-pull.txt---autostash
[2] https://git-scm.com/docs/git-stash/2.34.0#Documentation/git-stash.txt-pop--index-q--quietltstashgt
[3] https://github.com/git/git/commit/5fef3b15dbf609bdb13352d0eb716cd79c8ff017
[4] https://github.com/git/git/blob/master/contrib/completion/git-prompt.sh
[5] https://github.com/git/git/blob/e773545c7fe7eca21b134847f4fc2cbc9547fa14/contrib/completion/git-prompt.sh#L44-L46

Re: A bug or issue with "git rebase --autostash" not popping the stash automatically

From: Henk Smit <hidden>
Date: 2021-12-14 14:05:26

Hi Philippe,
You may, but I might not answer, or even receive your email. It is always
a better idea to write to the mailing list, and CC people that you want to
be made aware of your message :)
I was fighting inside my company to get people to realize how most of the
programmers try to stay away from git. They still work with our old versioning
system. And only clone a git workspace right before committing. It's a bit sad.
But all our git-experts kept telling me I was wrong. They expect everyone
to become a git-expert from day 1.
quoted
6) PROBLEM: the stash is not automatically popped.
Yes, that's the correct behaviour. If there are conflicts in the rebase, we do not apply the stash,
since it could make the situation even worse if the modifications in the stash also conflict with
the same lines as the rebase conflict. That fact, I realize, is missing from the documentation [1].
Maybe when there are problems with the rebase. But not when applying the stash back to your workspace.
I've tried 2.34, and there git works exactly like I expect! Even if there are conflicts with the stash,
they get applied (with the <<<< and >>>>).
So, the stash does not apply automatically, there are conflicts. As noted in [2], this is
the correct behaviour for 'git stash drop' [2].
OK. It's fine that when there are conflicts the stash is applied and then kept.
But what happened before 2.34 was that the stash wasn't even applied. Now it is. So my problem is solved.
What you describe is working as it should,  I think.
Well, it changed in 2.34 to behaviour that I expect.
I've had some discussion with our internal git-experts. And they all told me different things.
And when I asked very explicit things, like "what is the correct behaviour", they all admitted
that they didn't know. :) No problem, but it drove me a bit mad. That's why I wanted to ask
someone outside my company.

But now I have the answer. I was not crazy. And what I expect (apply the stash, even when there
are conflicts), is what should have happened.
quoted
Is this related to the issue you point out on the git mailing-list?
No, I was describing a case where the stash should have been applied automatically,
but it was not. This bug was fixed in Git 2.33.0 [3].
Understood. The behaviour was changed again in 2.34.
As I wrote above, the behaviour you are seeing is not a bug. When applying the stash would fail
due to conflicts, Git tells you about it:

         Applying autostash resulted in conflicts.
         Your changes are safe in the stash.
         You can run "git stash pop" or "git stash drop" at any time.

So it's up to you to remember to do it :)
Yep. But in 2.34 that changed again. Now the stash always gets applied.
If you want to have an "always-on" reminder that you have something stashed, you could use
'git-prompt.sh' [4], and set GIT_PS1_SHOWSTASHSTATE in your shell environment [5].
Thanks for the suggestion, I'll have a look at that.
quoted
So my question again: "is git rebase --autostash" supposed to always pop the stash or not?
If it is, is the current git behaviour a bug?
It's not, not when the rebase has conflicts, or when applying the stash results in conflicts.
Well, in 2.34, git thinks differently. :)

Anyway, thanks very much for your reply.
In 2.34, git behaves like I want.
This is behaviour I can tell my colleagues about (the ones who are not git-experts, like me).
"git fetch && git rebase --autostash" is now an easy and reliable way to update our workspaces.
That's all we need.
I'm happy.

Have a nice day,
henk.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help