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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux