git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* What's the recommendation for forgetting all rerere's records?
@ 2023-12-06 22:37 Sean Allred
  2023-12-08 23:19 ` Junio C Hamano
  0 siblings, 1 reply; 7+ messages in thread
From: Sean Allred @ 2023-12-06 22:37 UTC (permalink / raw)
  To: git

Hi all,

When outside the context of a conflict (no rebase/merge in progress),
what's the intended workflow to clear out the contents of
$GIT_DIR/rr-cache?

We have developers who'd like to discard their faulty resolutions after
completing a rebase gone awry (but not aborted). There doesn't seem to
be a recommendation in git-rerere(1) for how to deal with this
situation. (git-rerere-forget seems to only work in the context of an
active conflict -- and is documented as such.)

I'm wary of recommending `rm -rf "$(git rev-parse --git-dir)/rr-cache"`
-- it's hard to describe this as anything but hacky when the rest of the
experience is handled in porcelain.

Thanks!

--
Sean Allred

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

* Re: What's the recommendation for forgetting all rerere's records?
  2023-12-06 22:37 What's the recommendation for forgetting all rerere's records? Sean Allred
@ 2023-12-08 23:19 ` Junio C Hamano
  2023-12-15 12:21   ` Sean Allred
  0 siblings, 1 reply; 7+ messages in thread
From: Junio C Hamano @ 2023-12-08 23:19 UTC (permalink / raw)
  To: Sean Allred; +Cc: git

Sean Allred <allred.sean@gmail.com> writes:

> When outside the context of a conflict (no rebase/merge in progress),
> what's the intended workflow to clear out the contents of
> $GIT_DIR/rr-cache?

You could "rm -fr .git/rr-cache/??*" if you want.

The "intended" workflow is there will no need to "clear out" at all;
you may notice mistaken resolution, and you will remove it when you
notice one, but the bulk of the remaining database entries ought to
be still correct.

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

* Re: What's the recommendation for forgetting all rerere's records?
  2023-12-08 23:19 ` Junio C Hamano
@ 2023-12-15 12:21   ` Sean Allred
  2023-12-15 16:30     ` Junio C Hamano
  0 siblings, 1 reply; 7+ messages in thread
From: Sean Allred @ 2023-12-15 12:21 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Sean Allred, git


Junio C Hamano <gitster@pobox.com> writes:
> Sean Allred <allred.sean@gmail.com> writes:
>> When outside the context of a conflict (no rebase/merge in progress),
>> what's the intended workflow to clear out the contents of
>> $GIT_DIR/rr-cache?
>
> You could "rm -fr .git/rr-cache/??*" if you want.

Here's my reasoning for not wanting that:

>> I'm wary of recommending `rm -rf "$(git rev-parse --git-dir)/rr-cache"`
>> -- it's hard to describe this as anything but hacky when the rest of the
>> experience is handled in porcelain.

> The "intended" workflow is there will no need to "clear out" at all;
> you may notice mistaken resolution, and you will remove it when you
> notice one, but the bulk of the remaining database entries ought to
> be still correct.

When we noticed mistaken resolutions, rerere had already applied the
recorded resolution and there was no apparent way to return to the
conflicted state. If clearing out the rerere database was never an
intended workflow here, maybe _that's_ my actual question?

It seems likely this 'recovery' workflow should just be documented in
git-rerere.txt (which I'm happy to take on once I learn what that
workflow should be).

--
Sean Allred

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

* Re: What's the recommendation for forgetting all rerere's records?
  2023-12-15 12:21   ` Sean Allred
@ 2023-12-15 16:30     ` Junio C Hamano
       [not found]       ` <35f24a01d15ce28932bb6be098d6a164a49cc542008f75673cd6221a9b24b578@mu.id>
  0 siblings, 1 reply; 7+ messages in thread
From: Junio C Hamano @ 2023-12-15 16:30 UTC (permalink / raw)
  To: Sean Allred; +Cc: git

Sean Allred <allred.sean@gmail.com> writes:

> Junio C Hamano <gitster@pobox.com> writes:
>> Sean Allred <allred.sean@gmail.com> writes:
>>> When outside the context of a conflict (no rebase/merge in progress),
>>> what's the intended workflow to clear out the contents of
>>> $GIT_DIR/rr-cache?
>>
>> You could "rm -fr .git/rr-cache/??*" if you want.
>
> Here's my reasoning for not wanting that:
>
>>> I'm wary of recommending `rm -rf "$(git rev-parse --git-dir)/rr-cache"`
>>> -- it's hard to describe this as anything but hacky when the rest of the
>>> experience is handled in porcelain.

It is meant to be ugly ;-); the reason why the Porcelain does not
offer bulk erasure is because we want to strongly discourage it.

>> The "intended" workflow is there will no need to "clear out" at all;
>> you may notice mistaken resolution, and you will remove it when you
>> notice one, but the bulk of the remaining database entries ought to
>> be still correct.
>
> When we noticed mistaken resolutions, rerere had already applied the
> recorded resolution and there was no apparent way to return to the
> conflicted state.

The simplest is to go back to the original state before the merge
and then redo the operation without rerere enabled.

    $ git reset --hard
    $ git -c rerere.enabled=no merge <whatever arguments you used>

And you can redo the merge manually.

But more generally, after you incorrectly resolved a merge conflict,
whether you fumbled with your editor yourself or you let rerere kick
in to reuse your recorded resolution that you made in the past that
was faulty, before or after you run "git add" to tell the resolution
to the index, you should be able to do

    $ git checkout --merge <pathspec>

to tell Git to "unresolve" such paths.  Here is the relevant
paragraph from the "git checkout --help":

    When checking out paths from the index, this option lets you recreate the
    conflicted merge in the specified paths. This option cannot be used when
    checking out paths from a tree-ish.

The below is what I just did to demonstrate.  You can try the same
if you have our source code.  The first attempt will likely to
conflict because you do not have the rerere record, but you can
resolve the conflict in builtin/mv.c the way I did (shown by first
"git diff" in the sample transcript), and run "git rerere" (or just
"git commit -a" should also work) to record the resolution, and then
"git reset --hard" to obtain a sample rerere record you can use to
practice.

    # Just a sample merge I know will have a conflict
    $ SAMPLE=a59dbae0b3bd; # v2.43.0-rc0~126

    # Go to its parent and retry the merge with its second parent
    $ git checkout --detach $SAMPLE^1
    $ git merge $SAMPLE^2
    Auto-merging builtin/mv.c
    CONFLICT (content): Merge conflict in builtin/mv.c
    Resolved 'builtin/mv.c' using previous resolution.
    Automatic merge failed; fix conflicts and then commit the result.

    # We have conflict, and rerere kicked in.  Because I do not have
    # rerere.autoupdate configuration set, I can as "ls-files -u"
    # which paths are conflicting, but that is unnecessary (we
    # can see the path with conflict with the CONFLICT label above).
    $ git ls-files -u
    100644 665bd274485f6c76403e9230539e2650073a47f3 1	builtin/mv.c
    100644 05e7156034e04d637990cabf105f7fa967b0f2aa 2	builtin/mv.c
    100644 80fc7a3c7029603a0fcaf9d15d8432ed799b4909 3	builtin/mv.c

    # This is the resolution "rerere" gave me, which is what I did
    # back in August this year.  If you are following this example,
    # you'll first have to edit builtin/mv.c to hand resolve,
    # register the resolution to "rerere" database, and then run
    # "git reset --hard" to go back to the state before you did the
    # "git merge $SAMPLE^2" step to repeat.
    $ git diff
    diff --cc builtin/mv.c
    index 05e7156034,80fc7a3c70..0000000000
    --- i/builtin/mv.c
    +++ w/builtin/mv.c
    @@@ -304,8 -303,8 +304,8 @@@ int cmd_mv(int argc, const char **argv
                            goto act_on_entry;
                    }
                    if (S_ISDIR(st.st_mode)
     -		    && lstat(dst, &st) == 0) {
     +		    && lstat(dst, &dest_st) == 0) {
    - 			bad = _("cannot move directory over file");
    + 			bad = _("destination already exists");
                            goto act_on_entry;
                    }

    # Now the fun command you seem to have missed.  You MUST give
    # "git checkout --merge" a pathspec.  I do not encourage it but
    # using "." to say "unresolve everything under the sun" should
    # also work.
    $ git checkout --merge builtin/mv.c
    Recreated 1 merge conflict

    # Let's check the result.  We have recreated the conflicted
    # state in the working tree.
    $ git diff
    diff --cc builtin/mv.c
    index 05e7156034,80fc7a3c70..0000000000
    --- i/builtin/mv.c
    +++ w/builtin/mv.c
    @@@ -304,8 -303,8 +304,16 @@@ int cmd_mv(int argc, const char **argv
                            goto act_on_entry;
                    }
                    if (S_ISDIR(st.st_mode)
    ++<<<<<<< ours
     +		    && lstat(dst, &dest_st) == 0) {
     +			bad = _("cannot move directory over file");
    ++||||||| base
    ++		    && lstat(dst, &st) == 0) {
    ++			bad = _("cannot move directory over file");
    ++=======
    + 		    && lstat(dst, &st) == 0) {
    + 			bad = _("destination already exists");
    ++>>>>>>> theirs
                            goto act_on_entry;
                    }

    # You should then be able to correct the resolution with your
    # editor.
    $ edit builtin/mv.c

    # If this is one-time fix (you are happy with the original
    # resolution and wanted to deviate from it only once this time),
    # there is nothing else need to be done.  If you want to record
    # this as a new resolution, you'd get rid of the old one and
    # record this one.
    $ git rerere forget builtin/mv.c
    $ git rerere




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

* Re: What's the recommendation for forgetting all rerere's records?
       [not found]       ` <35f24a01d15ce28932bb6be098d6a164a49cc542008f75673cd6221a9b24b578@mu.id>
@ 2024-01-03  8:30         ` Sean Allred
  2024-01-03  9:27           ` Sean Allred
  0 siblings, 1 reply; 7+ messages in thread
From: Sean Allred @ 2024-01-03  8:30 UTC (permalink / raw)
  To: Sean Allred; +Cc: Junio C Hamano, Sean Allred, git


(Doesn't look like this actually got picked up by lore when I originally
sent it at Fri, 22 Dec 2023 12:19:50 -0600. This is a re-send; apologies
if you get this message twice.)

==

There might be a bug here.

Junio C Hamano <gitster@pobox.com> writes:
     # Now the fun command you seem to have missed.  You MUST give
     # "git checkout --merge" a pathspec.  I do not encourage it but
     # using "." to say "unresolve everything under the sun" should
     # also work.
     $ git checkout --merge builtin/mv.c
     Recreated 1 merge conflict

Yep, I definitely missed this! Very handy, thank you :-)

     # You should then be able to correct the resolution with your
     # editor.
     $ edit builtin/mv.c

     # If this is one-time fix (you are happy with the original
     # resolution and wanted to deviate from it only once this time),
     # there is nothing else need to be done.  If you want to record
     # this as a new resolution, you'd get rid of the old one and
     # record this one.
     $ git rerere forget builtin/mv.c
     $ git rerere

It's taken some time to investigate on our end, but it appears that the
issue we're seeing is particular to git-rebase.

Consider a run using git-merge, which works perfectly as you describe:

    # Let's set up our conflict; most output here elided for brevity.
    $ git init
    $ echo aaa >file
    $ git add file
    $ git commit -ambase
    $ git branch feature
    $ echo bbb >file
    $ git commit -amremote
    $ git switch feature
    $ echo ccc >file
    $ git commit -amlocal
    $ git --no-pager log --oneline --graph --all
    * 6b33f42 (HEAD -> feature) local
    | * 7e189f6 (main) remote
    |/
    * c5901f5 base

    # Now for the fun part!
    $ git config rerere.enabled true

    $ git merge main
    Auto-merging file
    CONFLICT (content): Merge conflict in file
    Recorded preimage for 'file'
    Automatic merge failed; fix conflicts and then commit the result.

    $ echo 'bad merge' >file
    $ git commit -ammerge
    Recorded resolution for 'file'.
    [feature 75d45f0] merge

    # Ack! That merge was bad. Let's try that again.
    $ git reset --hard @^
    HEAD is now at 6b33f42 local

    $ git merge main
    Auto-merging file
    CONFLICT (content): Merge conflict in file
    Resolved 'file' using previous resolution.
    Automatic merge failed; fix conflicts and then commit the result.

    # Your method to correct this single bad merge works flawlessly:
    $ git checkout --merge file
    Recreated 1 merge conflict

    $ git rerere forget file
    Updated preimage for 'file'
    Forgot resolution for 'file'

    $ echo 'good merge' >file

    $ git commit -ammerge
    Recorded resolution for 'file'.
    [feature 1770541] merge

Let's compare this with git-rebase:

    # Same setup as before
    $ git init
    $ echo aaa >file
    $ git add file
    $ git commit -ambase
    $ git branch feature
    $ echo bbb >file
    $ git commit -amremote
    $ git switch feature
    $ echo ccc >file
    $ git commit -amlocal
    $ git --no-pager log --oneline --graph --all
    * b4d7aeb (HEAD -> feature) local
    | * 2a0978d (main) remote
    |/
    * 91140a6 base

    # Now for the fun part! Just like before, but we're going to use
    # git-rebase instead of git-merge.
    $ git config rerere.enabled true

    $ git rebase main
    Auto-merging file
    CONFLICT (content): Merge conflict in file
    error: could not apply b4d7aeb... local
    hint: Resolve all conflicts manually, mark them as resolved with
    hint: "git add/rm <conflicted_files>", then run "git rebase --continue".
    hint: You can instead skip this commit: run "git rebase --skip".
    hint: To abort and get back to the state before "git rebase", run "git rebase --abort".
    Recorded preimage for 'file'
    Could not apply b4d7aeb... local

    $ echo 'bad merge' >file
    $ git add file

    $ EDITOR=: git rebase --continue
    file: needs merge
    You must edit all merge conflicts and then
    mark them as resolved using git add

    $ git rebase --abort

    $ git rebase main
    Auto-merging file
    CONFLICT (content): Merge conflict in file
    error: could not apply b4d7aeb... local
    hint: Resolve all conflicts manually, mark them as resolved with
    hint: "git add/rm <conflicted_files>", then run "git rebase --continue".
    hint: You can instead skip this commit: run "git rebase --skip".
    hint: To abort and get back to the state before "git rebase", run "git rebase --abort".
    Recorded preimage for 'file'
    Could not apply b4d7aeb... local

    $ git checkout --merge .
    Recreated 1 merge conflict

    $ git rerere forget .
    error: no remembered resolution for 'file'

    $ echo 'good merge' >file

    $ EDITOR=: git rebase --continue
    file: needs merge
    You must edit all merge conflicts and then
    mark them as resolved using git add

Is this a bug?

--
Sean Allred

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

* Re: What's the recommendation for forgetting all rerere's records?
  2024-01-03  8:30         ` Sean Allred
@ 2024-01-03  9:27           ` Sean Allred
  2024-02-10 17:18             ` Sean Allred
  0 siblings, 1 reply; 7+ messages in thread
From: Sean Allred @ 2024-01-03  9:27 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano


There was enough going on with that prior email that I gave it another
look and found some errors.

>     $ echo 'bad merge' >file
>     $ git add file
>
>     $ EDITOR=: git rebase --continue
>     file: needs merge
>     You must edit all merge conflicts and then
>     mark them as resolved using git add
>
>     $ git rebase --abort
>
>     $ git rebase main
>     Auto-merging file
>     CONFLICT (content): Merge conflict in file
>     error: could not apply b4d7aeb... local
>     hint: Resolve all conflicts manually, mark them as resolved with
>     hint: "git add/rm <conflicted_files>", then run "git rebase --continue".
>     hint: You can instead skip this commit: run "git rebase --skip".
>     hint: To abort and get back to the state before "git rebase", run "git rebase --abort".
>     Recorded preimage for 'file'
>     Could not apply b4d7aeb... local
>
>     $ git checkout --merge .
>     Recreated 1 merge conflict
>
>     $ git rerere forget .
>     error: no remembered resolution for 'file'
>
>     $ echo 'good merge' >file
>
>     $ EDITOR=: git rebase --continue
>     file: needs merge
>     You must edit all merge conflicts and then
>     mark them as resolved using git add

This section should have read:

    $ echo 'bad merge' >file
    $ git add file

    $ EDITOR=: git rebase --continue
    Recorded resolution for 'file'.
    [detached HEAD 5e3c431] local
     1 file changed, 1 insertion(+), 1 deletion(-)
    Successfully rebased and updated refs/heads/feature.

    $ git reset --hard @{1}
    HEAD is now at b4d7aeb local

    $ git rebase main
    Auto-merging file
    CONFLICT (content): Merge conflict in file
    error: could not apply b4d7aeb... local
    hint: Resolve all conflicts manually, mark them as resolved with
    hint: "git add/rm <conflicted_files>", then run "git rebase --continue".
    hint: You can instead skip this commit: run "git rebase --skip".
    hint: To abort and get back to the state before "git rebase", run "git rebase --abort".
    Resolved 'file' using previous resolution.
    Could not apply b4d7aeb... local

    $ git checkout --merge .
    Recreated 1 merge conflict

    $ git rerere forget .
    error: no remembered resolution for 'file'

I've driven myself a little nuts trying to reproduce it this morning,
but in doing so I've come to an important discovery: this bug presents
if `core.autocrlf=true` but does *not* present if `core.autocrlf=input`.

For completeness and future reference, the following script reproduces
the issue on Windows:

    git init
    echo aaa >file
    git add file
    git commit -ambase
    git branch feature
    echo bbb >file
    git commit -amremote
    git switch feature
    echo ccc >file
    git commit -amlocal
    git config rerere.enabled true
    git config core.autocrlf true     # <--

    # setup complete; let's rebase!
    git rebase main
    echo 'bad merge' >file
    git add file
    EDITOR=: git rebase --continue

    # uh oh; that was a bad resolution; let's try again
    git reset --hard @{1}
    git rebase main
    git checkout --merge .
    git rerere forget .               # fails
    echo 'good merge' >file
    git add file
    EDITOR=: git rebase --continue

At the end of this script, the 'bad merge' is still the recorded
resolution and no rerere record exists for the 'good merge'.

Just in case there's another piece of config somehow relevant, here's a
dump of the system that reproduced this:

    $ git config --list --show-scope | sort
    global	user.email=[clip]
    global	user.name=[clip]
    local	core.autocrlf=true
    local	core.bare=false
    local	core.filemode=false
    local	core.ignorecase=true
    local	core.logallrefupdates=true
    local	core.repositoryformatversion=0
    local	core.symlinks=false
    local	rerere.enabled=true
    system	core.autocrlf=input
    system	core.fscache=true
    system	core.fsmonitor=true
    system	core.symlinks=false
    system	credential.helper=manager
    system	credential.https://dev.azure.com.usehttppath=true
    system	diff.astextplain.textconv=astextplain
    system	filter.lfs.clean=git-lfs clean -- %f
    system	filter.lfs.process=git-lfs filter-process
    system	filter.lfs.required=true
    system	filter.lfs.smudge=git-lfs smudge -- %f
    system	http.sslbackend=schannel
    system	http.sslcainfo=C:/Program Files/Git/mingw64/etc/ssl/certs/ca-bundle.crt
    system	init.defaultbranch=main
    system	pull.rebase=true

    $ git --version
    git version 2.43.0.windows.1

It's worth noting at this point that while I believe I reproduced on
macOS last week, that doesn't jive with the available evidence (and I
can't reproduce it on macOS this morning, though I suspect that has more
to do with native use of LF over CRLF than anything else).

--
Sean Allred

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

* Re: What's the recommendation for forgetting all rerere's records?
  2024-01-03  9:27           ` Sean Allred
@ 2024-02-10 17:18             ` Sean Allred
  0 siblings, 0 replies; 7+ messages in thread
From: Sean Allred @ 2024-02-10 17:18 UTC (permalink / raw)
  To: Sean Allred; +Cc: git, Junio C Hamano


Sean Allred <allred.sean@gmail.com> writes:

> I've driven myself a little nuts trying to reproduce it this morning,
> but in doing so I've come to an important discovery: this bug presents
> if `core.autocrlf=true` but does *not* present if `core.autocrlf=input`.
>
> For completeness and future reference, the following script reproduces
> the issue on Windows:
>
>     [clip]
>
> At the end of this script, the 'bad merge' is still the recorded
> resolution and no rerere record exists for the 'good merge'.
>
> Just in case there's another piece of config somehow relevant, here's a
> dump of the system that reproduced this:
>
>     [clip]
>
> It's worth noting at this point that while I believe I reproduced on
> macOS last week, that doesn't jive with the available evidence (and I
> can't reproduce it on macOS this morning, though I suspect that has more
> to do with native use of LF over CRLF than anything else).

Is there a good way to convert this to a proper bug report without
losing the context?

--
Sean Allred

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

end of thread, other threads:[~2024-02-10 17:20 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-12-06 22:37 What's the recommendation for forgetting all rerere's records? Sean Allred
2023-12-08 23:19 ` Junio C Hamano
2023-12-15 12:21   ` Sean Allred
2023-12-15 16:30     ` Junio C Hamano
     [not found]       ` <35f24a01d15ce28932bb6be098d6a164a49cc542008f75673cd6221a9b24b578@mu.id>
2024-01-03  8:30         ` Sean Allred
2024-01-03  9:27           ` Sean Allred
2024-02-10 17:18             ` Sean Allred

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).