git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Wesley <wesleys@opperschaap.net>
To: phillip.wood@dunelm.org.uk
Cc: Junio C Hamano <gitster@pobox.com>, git@vger.kernel.org
Subject: Re: [PATCH 1/2] builtin/rebase.c: Emit warning when rebasing without a forkpoint
Date: Fri, 1 Sep 2023 13:13:37 -0400	[thread overview]
Message-ID: <a168fe69-f305-4280-b0e6-9406fbac796f@opperschaap.net> (raw)
In-Reply-To: <6127b570-5e9b-404f-9802-9135a1c9f31f@gmail.com>


Hello Phillip,


On 9/1/23 09:19, Phillip Wood wrote:
> 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]
> 
> 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?


  reply	other threads:[~2023-09-01 17:14 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-19 20:34 [PATCH 1/2] builtin/rebase.c: Emit warning when rebasing without a forkpoint Wesley Schwengle
2023-08-19 20:34 ` Wesley Schwengle
2023-08-31 20:57   ` Junio C Hamano
2023-08-31 21:52     ` Junio C Hamano
2023-09-01 13:33       ` Phillip Wood
2023-09-01 16:48         ` Junio C Hamano
2023-09-02 22:16       ` [PATCH v2] " Wesley Schwengle
2023-09-02 22:16         ` [PATCH v2 1/3] rebase.c: Make a distiction between rebase.forkpoint and --fork-point arguments Wesley Schwengle
2023-09-02 22:16         ` [PATCH v2 2/3] builtin/rebase.c: Emit warning when rebasing without a forkpoint Wesley Schwengle
2023-09-02 23:37           ` Junio C Hamano
2023-09-03  2:29             ` Wesley
2023-09-03  4:50             ` Junio C Hamano
2023-09-03 12:34               ` Wesley Schwengle
2023-09-05 22:01                 ` Junio C Hamano
2023-09-04 10:16               ` Phillip Wood
2023-09-02 22:16         ` [PATCH v2 3/3] git-rebase.txt: Add deprecation notice to the --fork-point options Wesley Schwengle
2023-09-01 13:19   ` [PATCH 1/2] builtin/rebase.c: Emit warning when rebasing without a forkpoint Phillip Wood
2023-09-01 17:13     ` Wesley [this message]
2023-09-01 18:10       ` Junio C Hamano
2023-09-02  1:35         ` Wesley
2023-09-02 22:36           ` Junio C Hamano
2023-08-19 20:34 ` [PATCH 2/2] git-rebase.txt: Add deprecation notice to the --fork-point options Wesley Schwengle
2023-08-31 14:44 ` [PATCH 1/2] builtin/rebase.c: Emit warning when rebasing without a forkpoint Wesley Schwengle

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=a168fe69-f305-4280-b0e6-9406fbac796f@opperschaap.net \
    --to=wesleys@opperschaap.net \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=phillip.wood@dunelm.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).