git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* Possible bug: git pull --rebase discards local commits
@ 2016-08-23 16:24 Joshua Phillips
  2016-08-23 19:28 ` Junio C Hamano
  0 siblings, 1 reply; 3+ messages in thread
From: Joshua Phillips @ 2016-08-23 16:24 UTC (permalink / raw)
  To: git

I've found a case where git pull --rebase discards commits in my branch
if the remote-tracking branch was rewound (and the remote tracking
branch's reflog contains my branch's latest commit). This is due to
git-pull's usage of git merge-base --fork-point.

On one hand, this behaviour might be correct since the remote repository
essentially removed that commit from master by 'reset --hard'. On the
other hand, I was surprised that git pull --rebase discarded a commit in
my branch.

Tested on 1.9.1, 2.7.4 and 2.10-rc1.

Steps to reproduce:

    # Set up initial repository
    git init source
    cd source
    git config receive.denyCurrentBranch no # make 'git push' work - not
    relevant to bug
    echo hello > test
    git add test
    git commit -m "Initial commit."

    # Clone repository, make and push two commits.
    cd ..
    git clone source clone
    cd clone
    echo greetings >> test
    git commit -a -m "This commit is rewritten."
    echo something >> test
    git commit -a -m "This commit disappears."
    git push origin master

    # Discard the second and rewrite the first commit.
    cd ../source
    git reset --hard HEAD~ # remove "This commit disappears"
    git commit --amend -m "This commit is a rewrite."
    cd ../clone

    # Observe that "This commit disappears" is still in our branch but
    is not in origin/master
    git fetch && git log --graph master origin/master

    # Now git pull --rebase gets confused because origin/master used to
    point to "This commit disappears",
    # so it assumes that that was the fork point for master, and "This
    commit disappears" is discarded.
    git pull --rebase
    git log --graph # "This commit disappears" is completely gone!

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

* Re: Possible bug: git pull --rebase discards local commits
  2016-08-23 16:24 Possible bug: git pull --rebase discards local commits Joshua Phillips
@ 2016-08-23 19:28 ` Junio C Hamano
  2017-03-10  0:23   ` Igor Djordjevic
  0 siblings, 1 reply; 3+ messages in thread
From: Junio C Hamano @ 2016-08-23 19:28 UTC (permalink / raw)
  To: Joshua Phillips; +Cc: git

Joshua Phillips <jphillips@imap.cc> writes:

> I've found a case where git pull --rebase discards commits in my branch
> if the remote-tracking branch was rewound (and the remote tracking
> branch's reflog contains my branch's latest commit). This is due to
> git-pull's usage of git merge-base --fork-point.
>
> On one hand, this behaviour might be correct since the remote repository
> essentially removed that commit from master by 'reset --hard'. On the
> other hand, I was surprised that git pull --rebase discarded a commit in
> my branch.

Yup, that sounds like a bad way to handle the situation.  After all,
the upstream may have first accepted your first attempt, and then
decided that it was premature and rewound it, expecting you to give
an improved reroll.  But I also agree with you that it may be
correct to drop it because the upstream already rejected it.

Since Git cannot tell between these two cases, we should play safer
than what the current code does, I would think.


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

* Re: Possible bug: git pull --rebase discards local commits
  2016-08-23 19:28 ` Junio C Hamano
@ 2017-03-10  0:23   ` Igor Djordjevic
  0 siblings, 0 replies; 3+ messages in thread
From: Igor Djordjevic @ 2017-03-10  0:23 UTC (permalink / raw)
  To: Junio C Hamano, Joshua Phillips; +Cc: git, Laszlo Kiss

Hi Junio,

On 23/08/2016 21:28, Junio C Hamano wrote:
> Joshua Phillips <jphillips@imap.cc> writes:
> > I've found a case where git pull --rebase discards commits in my branch
> > if the remote-tracking branch was rewound (and the remote tracking
> > branch's reflog contains my branch's latest commit). This is due to
> > git-pull's usage of git merge-base --fork-point.
> >
> > On one hand, this behaviour might be correct since the remote repository
> > essentially removed that commit from master by 'reset --hard'. On the
> > other hand, I was surprised that git pull --rebase discarded a commit in
> > my branch.
> 
> Yup, that sounds like a bad way to handle the situation.  After all,
> the upstream may have first accepted your first attempt, and then
> decided that it was premature and rewound it, expecting you to give
> an improved reroll.  But I also agree with you that it may be
> correct to drop it because the upstream already rejected it.
> 
> Since Git cannot tell between these two cases, we should play safer
> than what the current code does, I would think.

Were there any news in this regards so far? Would it be (more) 
sensible/safe to report the dropped commits, too? Something like:

  Dropping: Commit B
  Applying: Commit X
  Applying: Commit Y

... where "Applying: *" are standard "git rebase" output lines, and 
"Dropping: *" a newly proposed one (example graphs (1.1) to (1.3) 
shown below[1]).

That said, applied commits might even be considered pretty 
uninteresting here (as they`re kept/transferred over anyway), a noise 
drowning what otherwise might be really important - the dropped/lost 
ones...?

It does feel a bit scary learning that you may _silently_ lose 
commits, especially as --fork-point is used by default for both 
vanilla `git rebase` and `git pull --rebase`.

P.S. As a relatively new user, I actually just got aware of this 
behavior from another, recently posted e-mail[2], having me 
investigate further, yet thought replying here might be better as it 
got some attention already (adding author of that other e-mail, 
Laszlo Kiss, to Cc).

Regards,
Buga

[1] Example graphs:

  (1.1) ---A---B (master)
                \
                 X---Y (topic)

  (1.2)      C---D (master)
            /
        ---A---B
                \
                 X---Y (topic)

  (1.3)            X'---Y' (topic)
                  /
             C---D (master)
            /
        ---A

  Note that I didn`t use "origin/master" but just "master" on purpose, 
  as the branch being tracked doesn`t have to be a remote one, making 
  the lost local commits confusion even greater.

[2] https://public-inbox.org/git/CAO0LFki4PN8zz2xpoSpjTHJGS=NG_suQYR27EcmzEMiaCw9kuA@mail.gmail.com/

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

end of thread, other threads:[~2017-03-10  0:23 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-08-23 16:24 Possible bug: git pull --rebase discards local commits Joshua Phillips
2016-08-23 19:28 ` Junio C Hamano
2017-03-10  0:23   ` Igor Djordjevic

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).