Reputation: 100080
I was expecting git reset --soft
or git rebase
to squash several commits into one, but it's not really working at all in my case.
I have this bash script. It is intended to checkout a branch from the dev branch, squash commits, then we checkout another branch, delete some private files, then we push the result to the public remote.
I was advised to use tags to create places in the git history to squash back to, I think this makes sense, but for some reason the following script is not accomplishing its goal at all - no commit squashing seems to be happening at all.
npm version patch --force -m "Upgrade for several reasons" && # bump version
git add . &&
git add -A &&
git commit --allow-empty -am "publish/release:$1" &&
git push && # push to private/dev remote repo
git checkout dev_squash && # we do squashing on this branch
git merge dev -m "squashing" &&
# git reset --soft $(git describe --tags) &&
git rebase $(git describe --tags) &&
git add . &&
git add -A &&
git commit --allow-empty -am "publish/release:$1" &&
git tag xyz`date "+production-%Y%m%d%H%M%S"` &&
git checkout -b temp && # we checkout this branch to run deletes on private files
./delete-internal-paths.sh &&
git rm delete-internal-paths.sh -f &&
git add . &&
git add -A &&
git commit --allow-empty -am "publish/release:$1" &&
git push public HEAD:master -f &&
git checkout dev &&
git branch -D temp &&
npm publish .
as you can see I tried both git rebase
and git reset --soft
and neither did it for me. Any idea why it might not be working as intended?
Here's a visual:
Upvotes: 0
Views: 136
Reputation: 1325077
Try instead:
git checkout -b dev_squash $(git describe --tags --abbrev=0)
(note that --abbrev=0
is needed to get back the latest tag on develop
)
Actually, as discussed below, it is best to create once the dev_squash
branch from where dev
is starting:
git checkout -b dev_squash `(git merge-base dev master)`
Then keep that dev_squash
as a long-lived branch, and make git merge --squash dev
any time you need it: dev-squash branch will accumulate squashed commits.
And then:
git merge --squash dev
See also "In git, what is the difference between merge --squash
and rebase
?".
Upvotes: 1