I’ve got a branch I want to merge into another via a squash commit. In some cases these new files have leading or trailing spaces that are not needed. If I remove the extra spaces during the squash merge how do I push those changes into the original branch without having to manually do the fixes again?
Currently I am applying the changes twice. Once when I squash merge into a testing branch. And again when I squash merge the original branch into master.
My workflow
git co staging
git merge origin/feature --squash
git push origin staging
Do my checking, and then follow up with
git co master
git merge origin/feature --squash
git push origin master
It would be better to have a
pre-commithook which removes those trailing whitespace first, which means any further merge wouldn’t have any issue on that front.See for instance “Make git automatically remove trailing whitespace before committing“.
For you existing commit, you could you a
git reset --soft, combined with agit commit --all --amendin order to apply that post-commit hook to your last commit onfeature, before merging it tostaging/master.See “Practical uses of
git reset --soft?“.