git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Possible bug: git pull --rebase discards local commits

From
JPJoshua Phillips <jphillips@imap.cc>
Date
Aug 23, 2016, 16:24 UTC
Message-ID
<1471969497.3553135.703756633.0F6CCC4C@webmail.messagingengine.com>

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!
Next: Junio C Hamano
Message 1 of 3 in “Possible bug: git pull --rebase discards local commits”
  1. Joshua PhillipsAug 23, 2016
  2. Junio C HamanoAug 23, 2016
  3. Igor DjordjevicMar 10, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.