Rebase on reformatted release candidate - STORM-IRIT/Radium-Engine GitHub Wiki

UPDATE 2021

The easiest way to deal with format issue, is to perform a complete reformat on any histories that has badly formatted files.

With pre-commit.py, simply reapply pre-commit hook is the easiest way to do that. See here for source of this process.

First save a copy of your branch in its current stage:

git branch SAVE-to-compare

then we replay all commits, reset/add them again, so it trigger pre-commit, and reformat.

git rebase --strategy-option=theirs -x 'git reset --soft HEAD~1 && git commit -C HEAD@{1}' origin/release-candidate

in case of conflict

git add -u && git commit -C HEAD@{1} && \
git rebase --continue                   

in case of empty commit (e.g. if pre-commit ci commits some code formatting, that have already been done during rebase)

git rebase --continue

To check if everything went well, you can compare code patch before/after the reformatting rebase

git format-patch origin/release-candidate --stdout > after.patch 
git switch SAVE-to-compare
git format-patch origin/release-candidate --stdout > before.patch 
# remove commit number and sha
cat after.patch |grep -v From | grep -v Subject > after-clean.patch
cat before.patch |grep -v From | grep -v Subject > before-clean.patch
diff --suppress-blank-empty -EwZbB before-clean.patch after-clean.patch

You can check any differences, and digg into diff after.patch before.patch (or better using meld with ignore spaces filter) to inspect the corresponding commmits.

How to deal with style

PR#575 apply code style to all files.

To easily update on reformatted master, the idea is to first create a temporary version of master with all the modification except format, rebase on this noformat version, and reapply formatting.

As an alternative, you can directly rebase on formatted master, and on any conflict first reformat your file then compare and merge.

this has not been deeply tested, use with caution, understand what you do

first clean you history, it will ease further merges (as usual rebase -i on the first commit you don't want to touch, squash and fix) SAVE YOUR BRANCH BEFORE ANY REBASE/FORCE PUSH

then prepare rebase, by creating a master without reformating:

git fetch
git checkout origin/master
git checkout -b noformat
# do not pick *** format only *** commits in the rebase
git rebase -i cd71758a5

rebase your branch on this noformat branch, resolve appropriately conflicts

git checkout mybranch
git rebase -i noformat

then rebase on master, see below how to manage conflict

git rebase -i origin/master

in case of conflict take your branch version (ie REMOTE version in the case of a rebase). then format after each merge, before rebase --continue and add all modified files (git add -u). To this end you can call clang-format on the modified files, use script that format all ./scripts/format-all.sh or use the gh-formatter trick, but it's longer ... the new master have a github action associated with the branch gh-formatter, whenever you push on this branch, it reformat all the file and add a "*** format only ***" commit with all the modifications.

git checkout -b gh-formatter
git push --set-upstream yourrepo

wait end of github action

git pull
git checkout mybranch
git reset --hard gh-formatter
git push

Double check everything is fine, git diff origin/master and git diff myrepo/mybranch could help.