git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Why does "git pull --rebase" require a clean git directory?
@ 2020-12-10 22:15 Shupak, Vitaly
  2020-12-11  3:42 ` brian m. carlson
  2020-12-11 13:46 ` Phillip Susi
  0 siblings, 2 replies; 5+ messages in thread
From: Shupak, Vitaly @ 2020-12-10 22:15 UTC (permalink / raw)
  To: git

Hi,

"git pull --rebase" requires having NO uncommitted changes, even if the locally modified files haven't been updated upstream, or even if there are no changes to upstream at all. I know I could use --autostash, but that's inefficient and may be undesirable if it would create a conflict.

Would it be possible to change the behavior of "git pull --rebase" so that it only fails if the locally modified files conflict with the files modified upstream (similar to the default git pull behavior without --rebase)?

Thanks,
Vitaly


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

* Re: Why does "git pull --rebase" require a clean git directory?
  2020-12-10 22:15 Why does "git pull --rebase" require a clean git directory? Shupak, Vitaly
@ 2020-12-11  3:42 ` brian m. carlson
  2020-12-11 21:23   ` Shupak, Vitaly
  2020-12-11 13:46 ` Phillip Susi
  1 sibling, 1 reply; 5+ messages in thread
From: brian m. carlson @ 2020-12-11  3:42 UTC (permalink / raw)
  To: Shupak, Vitaly; +Cc: git

[-- Attachment #1: Type: text/plain, Size: 1979 bytes --]

On 2020-12-10 at 22:15:11, Shupak, Vitaly wrote:
> Hi,
> 
> "git pull --rebase" requires having NO uncommitted changes, even if
> the locally modified files haven't been updated upstream, or even if
> there are no changes to upstream at all. I know I could use
> --autostash, but that's inefficient and may be undesirable if it would
> create a conflict.
> 
> Would it be possible to change the behavior of "git pull --rebase" so
> that it only fails if the locally modified files conflict with the
> files modified upstream (similar to the default git pull behavior
> without --rebase)?

I suspect the reason for the difference is in how the two pieces of code
work.  A merge in general can work in a dirty tree whereas a rebase
cannot.  That, in turn, is because the merge code merges two files
internally and then writes them out to the working tree, whereas the
rebase code, at least in some cases, doesn't contain the same
precautions not to modify the working tree.

Moreover, a merge is a single operation, so it's safe to operate on a
commit and then give up.  A rebase consists of multiple operations, so
we'd have to evaluate each operation and synthesize it, internally
performing the merge (or apply) that's a part of it, in order to
determine if it would conflict.  Otherwise, we'd have to just try it and
somehow abort cleanly in the middle without otherwise dirtying the
working tree.  Right now, that abort step involves a reset --hard, which
is going to blow away your data.

So is it possible to do?  Sure.  Is it easy?  Not especially with the
current code.  So certainly it could be done if it were important to
someone, but it will likely be a good bit of work.

Sorry this wasn't the news you were hoping for.  I'd love to have some
easy solution that I could offer to send in a patch for this weekend to
solve this, but unfortunately it's not that easy.
-- 
brian m. carlson (he/him or they/them)
Houston, Texas, US

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 263 bytes --]

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

* Re: Why does "git pull --rebase" require a clean git directory?
  2020-12-10 22:15 Why does "git pull --rebase" require a clean git directory? Shupak, Vitaly
  2020-12-11  3:42 ` brian m. carlson
@ 2020-12-11 13:46 ` Phillip Susi
  1 sibling, 0 replies; 5+ messages in thread
From: Phillip Susi @ 2020-12-11 13:46 UTC (permalink / raw)
  To: Shupak, Vitaly; +Cc: git


Shupak, Vitaly writes:

> "git pull --rebase" requires having NO uncommitted changes, even if
> the locally modified files haven't been updated upstream, or even if
> there are no changes to upstream at all. I know I could use

It isn't just about whether upstream has changed those same files, but
also would fail if any of your commits have.

> --autostash, but that's inefficient and may be undesirable if it would
> create a conflict.

If that creates a conflict, then the pull would definitely fail if it
had been attempted.

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

* RE: Why does "git pull --rebase" require a clean git directory?
  2020-12-11  3:42 ` brian m. carlson
@ 2020-12-11 21:23   ` Shupak, Vitaly
  2020-12-12 11:29     ` brian m. carlson
  0 siblings, 1 reply; 5+ messages in thread
From: Shupak, Vitaly @ 2020-12-11 21:23 UTC (permalink / raw)
  To: brian m. carlson; +Cc: git

Thanks for the explanation. It seems like some optimizations may still be possible. For example, if the pull could be done with a fast-forward merge, then you don't need to rebase at all. This could be an option like pull.rebase=noffonly.

-----Original Message-----
From: brian m. carlson <sandals@crustytoothpaste.net> 
Sent: Thursday, December 10, 2020 10:42 PM
To: Shupak, Vitaly <Vitaly.Shupak@deshaw.com>
Cc: git@vger.kernel.org
Subject: Re: Why does "git pull --rebase" require a clean git directory?

On 2020-12-10 at 22:15:11, Shupak, Vitaly wrote:
> Hi,
> 
> "git pull --rebase" requires having NO uncommitted changes, even if 
> the locally modified files haven't been updated upstream, or even if 
> there are no changes to upstream at all. I know I could use 
> --autostash, but that's inefficient and may be undesirable if it would 
> create a conflict.
> 
> Would it be possible to change the behavior of "git pull --rebase" so 
> that it only fails if the locally modified files conflict with the 
> files modified upstream (similar to the default git pull behavior 
> without --rebase)?

I suspect the reason for the difference is in how the two pieces of code work.  A merge in general can work in a dirty tree whereas a rebase cannot.  That, in turn, is because the merge code merges two files internally and then writes them out to the working tree, whereas the rebase code, at least in some cases, doesn't contain the same precautions not to modify the working tree.

Moreover, a merge is a single operation, so it's safe to operate on a commit and then give up.  A rebase consists of multiple operations, so we'd have to evaluate each operation and synthesize it, internally performing the merge (or apply) that's a part of it, in order to determine if it would conflict.  Otherwise, we'd have to just try it and somehow abort cleanly in the middle without otherwise dirtying the working tree.  Right now, that abort step involves a reset --hard, which is going to blow away your data.

So is it possible to do?  Sure.  Is it easy?  Not especially with the current code.  So certainly it could be done if it were important to someone, but it will likely be a good bit of work.

Sorry this wasn't the news you were hoping for.  I'd love to have some easy solution that I could offer to send in a patch for this weekend to solve this, but unfortunately it's not that easy.
--
brian m. carlson (he/him or they/them)
Houston, Texas, US

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

* Re: Why does "git pull --rebase" require a clean git directory?
  2020-12-11 21:23   ` Shupak, Vitaly
@ 2020-12-12 11:29     ` brian m. carlson
  0 siblings, 0 replies; 5+ messages in thread
From: brian m. carlson @ 2020-12-12 11:29 UTC (permalink / raw)
  To: Shupak, Vitaly; +Cc: git

[-- Attachment #1: Type: text/plain, Size: 677 bytes --]

On 2020-12-11 at 21:23:23, Shupak, Vitaly wrote:
> Thanks for the explanation. It seems like some optimizations may still
> be possible. For example, if the pull could be done with a
> fast-forward merge, then you don't need to rebase at all. This could
> be an option like pull.rebase=noffonly.

Yeah, I agree that if our operation is a fast-forward, that could be
done in a pretty straightforward way.  It's still a little tricky
because of how the current code works (the fast-forward logic is in the
sequencer, which gets called after the check), but it's something that
we could add more easily.
-- 
brian m. carlson (he/him or they/them)
Houston, Texas, US

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 263 bytes --]

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

end of thread, other threads:[~2020-12-12 11:30 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-10 22:15 Why does "git pull --rebase" require a clean git directory? Shupak, Vitaly
2020-12-11  3:42 ` brian m. carlson
2020-12-11 21:23   ` Shupak, Vitaly
2020-12-12 11:29     ` brian m. carlson
2020-12-11 13:46 ` Phillip Susi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).