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?


  • Clone a repo with submodules: override credentials
  • Intellij import issue - Cannot run program “git”: error=2, No such file or directory
  • How to avoid detached headstate in git?
  • Git doesn't detect rename when file has been modified significantly after move
  • git assume unchanged vs skip worktree - ignoring a symbolic link
  • how to merge cloned git repository with the original repository
  • > 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,, I could get to the interactive rebase easily enough, but how could I work with that from a node script?


  • How to handle username/passwords at continuous integration environment with Jenkins, Git and Gradle?
  • How to automatically rename tags using git hooks?
  • What is git-daemon?
  • How can I move the entire git repository somewhere else?
  • Pitfalls when upgrading to a new version of Git
  • Accidentally merged github repo into personal project
  • 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 add.

    Git Baby is a git and github fan, let's start git clone.