Skip to content

Instantly share code, notes, and snippets.

@comm1x
Created June 29, 2021 09:49
Show Gist options
  • Save comm1x/e079361a944f4624d3b90bdba47d99c6 to your computer and use it in GitHub Desktop.
Save comm1x/e079361a944f4624d3b90bdba47d99c6 to your computer and use it in GitHub Desktop.
#!/usr/bin/env node
const { execSync, spawn } = require('child_process');
const chalk = require('chalk');
function hasChangesInRepo() {
return execSync('git status --porcelain').toString().length > 0;
}
if (hasChangesInRepo()) {
console.error('Error: there are changes in the repo. Can\'t start squashing.');
return;
}
const lastCommitMessage = execSync('git log -1 --pretty=%B').toString().trim();
if (!lastCommitMessage) {
throw new Error('Unable to get message of last commit');
}
execSync('git reset --soft HEAD~2');
spawn('git', ['commit', '-m', lastCommitMessage], {stdio:'inherit'});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment