Can git commits be squashed from a node.js script?
I would like to be able to squash the last n commits that have a commit message of ‘squash commit’ into a single commit from a node.js script. The only way that I know of to squash commits is through an interactive rebase, is there a way to do this from a node script?
> git log --oneline | head -4 ecce153 Do not change commit dd831f6 squash commit c20677a squash commit 86b52fb squash commit > ./squash.js "New commit made by squashing 3 'squash commit' commits." ecce153 Do not change commit as34dwf New commit made by squashing 3 'squash commit' commits.
Going off of this SO post, https://stackoverflow.com/a/5956198/626759, I could get to the interactive rebase easily enough, but how could I work with that from a node script?
One Solution collect form web for “Can git commits be squashed from a node.js script?”
You don’t need to do a rebase to squash n commits:
git reset HEAD~4 git add . git commit -m "squashed four commits"
This backs up HEAD four commits, but preserves the present changes in the working directory, then adds and commits those changes in a single commit.
Even shorter version
git reset --soft HEAD~4 git commit -m "squashed four commits"
--soft preserves the index too, so you don’t have to