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 log 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
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
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
Links or onliners that save my git life
Split a commit in two : interactive rebase, edit the commit of interest, reset HEAD^, recommit in as many splits as you want, git rebase –continue
Sometimes, I have a branch with a new feature I work on, call it
At some point I want to show this feature to colleagues, so I want to have a clean history, and remove some WIP stuff
To this end :
git checkout Feature_mess
git checkout -b Feature_clean
git rebase -i Feature_clean master (or whatever base you want)
Cleanup history here, remove crappy things, merge a lot of commits, rewrite history !
Now to benefit from this clean history as a base of
git branch temp Feature_mess
git checkout temp
git reset --soft Feature_clean
Now you are in the state of mess, with the history of cleanup, you can check diff and then
Et voilà !
More information on
git reset here : https://gist.github.com/tnguyen14/0827ae6eefdff39e452b