git/list[1] front-page[2] threads[3] people[4] search[5] about
wed 2026-10-07 18:11 UTC

Re: [PATCH 1/2] builtin/rebase.c: Emit warning when rebasing without a forkpoint

From
Wesley <wesleys@opperschaap.net>
Date
Sep 1, 2023, 17:13 UTC
Message-ID
<a168fe69-f305-4280-b0e6-9406fbac796f@opperschaap.net>
In-Reply-To
<6127b570-5e9b-404f-9802-9135a1c9f31f@gmail.com>
Hello Phillip,
On 9/1/23 09:19, Phillip Wood wrote:
Show 39 quoted lines
> Hi Wesley
> 
> On 19/08/2023 21:34, Wesley Schwengle wrote:
>> When commit d1e894c6d7 (Document `rebase.forkpoint` in rebase man page,
>> 2021-09-16) was submitted there was a discussion on if the forkpoint
>> behaviour of `git rebase' was sane. In my experience this wasn't sane.
>> Git rebase doesn't work if you don't have an upstream branch configured
>> (or something that says `merge = refs/heads/master' in the git config).
>> The behaviour of `git rebase' was that if you supply an upstream on the
>> command line that it behaves as if `--no-forkpoint' was supplied and if
>> you don't supply an upstream, it behaves as if `--forkpoint' was
>> supplied. This can result in a loss of commits if you don't know that
>> and if you don't know about `git reflog' or have other copies of your
>> changes. This can be seen with the following reproduction path:
>>
>>      mkdir reproduction
>>      cd reproduction
>>      git init .
>>      echo "commit a" > file.txt
>>      git add file.txt
>>      git commit -m "First commit" file.txt
>>      echo "commit b" >> file.txt
>>      git commit -m "Second commit" file.txt
>>
>>      git switch -c foo
>>      echo "commit c" >> file.txt"
>>      git commit -m "Third commit" file.txt
>>      git branch --set-upstream-to=master
>>
>>      git status
>>      On branch foo
>>      Your branch is ahead of 'master' by 1 commit.
>>
>>      git switch master
>>      git merge foo
> 
> Here "git merge" fast-forwards I think, if instead it created a merge 
> commit there would be no problem as the tip of branch "foo" would not 
> end up in master's reflog.
If you do

git merge foo --no-ff git reset --hard HEAD^ git switch foo git rebase

You'll end up with just the commits that are in master. You'll lose all commits from foo.

>>      git log --format='%C(yellow)%h%Creset %Cgreen%s%Creset'
> 
> For a reproduction recipe I think "git log --oneline" would suffice.
Will update, thanks.
 >> [snip]
Show 5 quoted lines
> 
> Thanks for the detailed reproduction recipe, I think it would be helpful 
> to summarize what's happening in the commit message, especially as it 
> seems to depend on "git merge" fast-forwarding. Do you often merge a 
> branch into it's upstream and then reset the upstream branch?

Tricky question. When I encountered this behavior I was working on an epic/topic branch that I had locally. And I made a commit that I thought should have been in another branch. I moved the commit to another branch and than later on rebased it.

I didn't reply to Juno yet, but he refers to the discussion about --fork-point and --root command line options. This discussion links to a blogpost [*1*] where the same behavior is experienced.

The quirk is this: --fork-point looks at the reflog and reflog is local. Meaning, having an remote upstream branch will make --fork-point a noop. Only where you have an upstream which is local and your reflog has seen dropped commits it does something. In all other cases (including supplying the upstream) it behaves as if --no-fork-point was set. If you do the same action in two different clones, you get a different result, depending on what is in your reflog. I find this very tricky behavior for a default. I've set it to false myself, to get a more consistent behavior.

I usually have a remote upstream (gitlab/github) and work with that, so the --fork-point behaviour isn't present because there is no reflog for that, so it behaves as --no-fork-point.

Cheers, Wesley

[1]: https://commaok.xyz/post/fork-point/
-- 
Wesley

Why not both?
Previous: Junio C HamanoNext: Junio C Hamano
Message 10 of 23 in “builtin/rebase.c: Emit warning when rebasing without a forkpoint”
  1. 1/2 builtin/rebase.c: Emit warning when rebasing without a forkpointWesley Schwengle, Aug 19, 2023
  2. 1/2 builtin/rebase.c: Emit warning when rebasing without a forkpointWesley Schwengle, Aug 19, 2023
  3. 2/2 git-rebase.txt: Add deprecation notice to the --fork-point optionsWesley Schwengle, Aug 19, 2023
  4. Wesley SchwengleAug 31, 2023
  5. Junio C HamanoAug 31, 2023
  6. Junio C HamanoAug 31, 2023
  7. Phillip WoodSep 1, 2023
  8. Phillip WoodSep 1, 2023
  9. Junio C HamanoSep 1, 2023
  10. WesleySep 1, 2023
  11. Junio C HamanoSep 1, 2023
  12. WesleySep 2, 2023
  13. Emit warning when rebasing without a forkpointWesley Schwengle, Sep 2, 2023
  14. 2/3 builtin/rebase.c: Emit warning when rebasing without a forkpointWesley Schwengle, Sep 2, 2023
  15. 1/3 rebase.c: Make a distiction between rebase.forkpoint and --fork-point argumentsWesley Schwengle, Sep 2, 2023
  16. 3/3 git-rebase.txt: Add deprecation notice to the --fork-point optionsWesley Schwengle, Sep 2, 2023
  17. Junio C HamanoSep 2, 2023
  18. Junio C HamanoSep 2, 2023
  19. WesleySep 3, 2023
  20. Junio C HamanoSep 3, 2023
  21. Wesley SchwengleSep 3, 2023
  22. Phillip WoodSep 4, 2023
  23. Junio C HamanoSep 5, 2023

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.