Alexander Mills Alexander Mills - 1 year ago 91
Git Question

git rebase <tag> / git reset --soft <tag> is not working

I was expecting

git reset --soft
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
./ &&
git rm -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
git reset --soft
and neither did it for me. Any idea why it might not be working as intended?

Here's a visual:

enter image description here

Answer Source

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)

And then:

git merge --squash dev

See also "In git, what is the difference between merge --squash and rebase?".

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