29

Git rerere provides for reuse of previous conflict resolutions during rebase, and can even stage the resolved files by setting rerere.autoupdate = True (as detailed in another question). However, even if all conflicts are resolved and all files staged, I still have to run git rebase --continue to continue the rebase operation.

How can I automatically continue if rerere has resolved all conflicts and staged all changes?

2
  • 3
    Another question has a nice answer stackoverflow.com/a/27513648/259946
    – hazzik
    Commented Jun 23, 2015 at 4:11
  • I don't know if @frasertweedale meant the question this way, but I'm using git rebase -i in a script (with GIT_SEQUENCE_EDITOR). So not automatically continuing/skipping resolved conflicts is a PITA, because either I have to do it manually or emulate the nicety of if ! git rebase […]; then git rebase --abort; fi with lots of git reset, git cherry-pick, etc. and thus lots of opportunities to mess up. Commented Dec 31, 2016 at 8:23

2 Answers 2

7

2017: Rebase should use more the rerere-autoupdate from Git 2.14.x/2.15 onward (Q3 2017).

See commit f826fb7, commit 8d8cb4b, commit 6f0e577, commit 9b6d7a6, commit 5fb415b, commit fd4a3f4 (02 Aug 2017) by Phillip Wood (phillipwood).
(Merged by Junio C Hamano -- gitster -- in commit 1016495, 22 Aug 2017)

That is because now:

rebase: honor --rerere-autoupdate

Rebase accepts '--rerere-autoupdate' as an option but only honors it if '-m' is also given.
Fix it for a non-interactive rebase by passing on the option to 'git am' and 'git cherry-pick'.

And:

rebase -i: honor --rerere-autoupdate

Interactive rebase was ignoring '--rerere-autoupdate'.
Fix this by reading it appropriate file when restoring the sequencer state for an interactive rebase and passing '--rerere-autoupdate' to merge and cherry-pick when rebasing with '--preserve-merges'.


However, as I mentioned here, Starting Git 2.22, Q2 2019, the old rebase script is no more.

As mentioned by Ohad Schneider in the comments:

Even when I run rebase main --rerere-autoupdate, I still need to manually execute rebase --continue upon each conflict, so the original ask of the OP (something like --rerere-autocontinue) still doesn't exist, right?

It appears to be so: I try the following test script with git version 2.45.2.windows.1 (Q2 2024):

#!/bin/bash

# Exit immediately if a command exits with a non-zero status
set -e

echo "**** Creating a new directory for the repository and navigating into it ****"
rm -rf git-rerere-test
mkdir git-rerere-test
cd git-rerere-test

echo "**** Initializing a new Git repository ****"
git -c init.defaultBranch=master init
git config init.defaultBranch master
git config user.name "Test User"
git config user.email "[email protected]"

echo "**** Creating the initial commit on the master branch ****"
echo "Initial content" > F1
git add F1
git commit -m "Initial commit on master"

echo "**** Creating a new branch called 'topic' ****"
git checkout -b topic

echo "**** Committing a change on the topic branch ****"
echo "Content on topic branch" > F2
git add F2
git commit -m "Commit F2 on topic branch"

echo "**** Checking out back to master and making another commit ****"
git checkout master
echo "Different content on master branch" > F2
git add F2
git commit -m "Commit F2 on master branch"

echo "**** Making another commit on the master branch to create a conflict ****"
echo "Content on master branch after F2" > F3
git add F3
git commit -m "Commit F3 on master branch"

echo "**** Going back to the topic branch and making another conflicting commit ****"
git checkout topic
echo "Conflicting content on topic branch" > F3
git add F3
git commit -m "Commit F3 on topic branch"

echo "**** Enabling rerere and autoupdate ****"
git config rerere.enabled true
git config rerere.autoupdate true

echo "**** Attempting to rebase the topic branch onto master with rerere-autoupdate ****"
if git rebase --rerere-autoupdate master; then
    echo "**** Rebase completed without conflicts. ****"
else
    echo "**** Rebase stopped due to conflicts. Resolving... ****"
fi

# At this point, rerere should have resolved conflicts automatically
echo "**** Checking the status to ensure there are no remaining conflicts ****"
if git rebase --continue; then
    echo "**** Rebase continued automatically. ****"
else
    echo "**** Rebase requires manual intervention. ****"
    exit 1
fi

# Resolve any remaining conflicts manually (if any)
echo "**** Manually resolving any remaining conflicts... ****"
echo "Resolved content" > F2
git add F2
echo "Resolved content" > F3
git add F3

echo "**** Continuing the rebase process ****"
if git rebase --continue; then
    echo "**** Rebase completed successfully after manual conflict resolution. ****"
else
    echo "**** Rebase failed. Manual intervention required. ****"
    exit 1
fi

echo "**** Cleaning up ****"
cd ..
rm -rf git-rerere-test

echo "**** Test repository and files cleaned up. ****"

And I still get "Rebase requires manual intervention" (instead of "Rebase completed successfully after manual conflict resolution"):

C:\Users\vonc\prog\git\so\30771707>bash -c "./testrebrerere.sh t1"
**** Creating a new directory for the repository and navigating into it ****
**** Initializing a new Git repository ****
Initialized empty Git repository in /mnt/c/Users/vonc/prog/git/so/30771707/git-rerere-test/.git/
**** Creating the initial commit on the master branch ****
[master (root-commit) 33cae77] Initial commit on master
 1 file changed, 1 insertion(+)
 create mode 100644 F1
**** Creating a new branch called 'topic' ****
Switched to a new branch 'topic'
**** Committing a change on the topic branch ****
[topic adee62d] Commit F2 on topic branch
 1 file changed, 1 insertion(+)
 create mode 100644 F2
**** Checking out back to master and making another commit ****
Switched to branch 'master'
[master e79e48f] Commit F2 on master branch
 1 file changed, 1 insertion(+)
 create mode 100644 F2
**** Making another commit on the master branch to create a conflict ****
[master 4161fe7] Commit F3 on master branch
 1 file changed, 1 insertion(+)
 create mode 100644 F3
**** Going back to the topic branch and making another conflicting commit ****
Switched to branch 'topic'
[topic 5a6205f] Commit F3 on topic branch
 1 file changed, 1 insertion(+)
 create mode 100644 F3
**** Enabling rerere and autoupdate ****
**** Attempting to rebase the topic branch onto master with rerere-autoupdate ****
Auto-merging F2
CONFLICT (add/add): Merge conflict in F2
error: could not apply adee62d... Commit F2 on topic branch
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 'F2'
Could not apply adee62d... Commit F2 on topic branch
**** Rebase stopped due to conflicts. Resolving... ****
**** Checking the status to ensure there are no remaining conflicts ****
F2: needs merge
You must edit all merge conflicts and then
mark them as resolved using git add
**** Rebase requires manual intervention. ****
8
  • 2
    Note that this does not work for rebase --continue, i.e. you already need to specify it for the initial rebase command.
    – jmiserez
    Commented Jul 19, 2018 at 12:28
  • I guess this "automatic continue" never materialized? Commented Jul 10 at 18:23
  • @OhadSchneider Not for rebase --continue, no.
    – VonC
    Commented Jul 13 at 23:45
  • 1
    @OhadSchneider It does not seem to be effective indeed. I have included your comment in the answer for more visibility, as well as a test script: if you see any issue with said test script, I would be interested in any fix.
    – VonC
    Commented Jul 14 at 20:11
  • 1
    @OhadSchneider I was trying to translate t3418-rebase-continue.sh, but I suspect the Git testing framework does more than I saw when writung that bash script.
    – VonC
    Commented Jul 15 at 12:25
3

No. Rebase or Merge does not automatically provide a provision for auto-commits when conflicts arise. You could understand more about git merge here in 'merging' heading. git config also does not provide an option for auto commits while rebasing. Note that you could choose not-to commit while merging.

Not the answer you're looking for? Browse other questions tagged or ask your own question.