Jason Jason - 4 years ago 130
Git Question

How to push changes from a squash merge back into source branch

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

Answer Source

It would be better to have a pre-commit hook 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 a git commit --all --amend in order to apply that post-commit hook to your last commit on feature, before merging it to staging/master.

See "Practical uses of git reset --soft?".

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download