Tag Archives: bash

Magic rebase and (re-) format

If you like clean coherent formatted code, you may already use something like clang-format and git hook to ensure format when commit

If you like clean history, you might use a lot of rebase.

Sometimes during conflit, format is lost, but it’s pita to fix it afterwards without introducing some commit out of the clean history

Update 2022-05-10

I have switch to pre-commit.ci to perform pre-commit hook and formating, applying the same principle, I run

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

Which reset and reapply commits, hence triggering pre-commit hook. Then conflict resolution is nearly the same, I use the following oneliner to fix all possible conflicts

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

Older version

I use run-clang-format script with rebase and exec. This will stop rebase if format is not respected

git rebase --exec "./run-clang-format.py -r -i \
--style file --extensions inl,cpp,hpp src/" \

When it stops, you can examine the situation with

git status
git diff

Once everything looks good (in case of conflict, simply use remote, and reformat)

git add -u && \
git commit -m"fix format" && \
git rebase --continue

Then rebase -i again so you can squash/fix all “fix format” commits with their immediate ancestor.

TODO : explain a bit more

My one line usefull commands

convert png file, keeping full color (either convert will reduce color space to 1bit our colormap) if it do not loose anything
Apply convert @ -crop 600x580+100+0 -gravity Center -auto-level -define png:format=png32 output/@ to *

Copy a webpage for local viewing, recursive but not the entire www 😉

wget -r -k -Dhost.com http://www.host.com/webpage

ubuntu package related :

dpkg -l nvidia* #list all package starting with nvidia
dpkg -S /usr/include/GL/glext.h #find which package provide a file