Created
April 21, 2022 09:13
-
-
Save jsullivanlive/aa40cb972b739add2508397e759d2689 to your computer and use it in GitHub Desktop.
rebase hundreds of automated commits into linear history
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const util = require('util'); | |
const exec = util.promisify(require('child_process').exec); | |
const ex = async (cmd) => { | |
console.log({cmd}); | |
return exec(cmd).then(console.log); | |
} | |
async function run(branch) { | |
try { | |
await ex(`git switch ${branch}`); | |
await ex(`git rebase master -X ours`); | |
await ex(`git switch master`); | |
await ex(`git merge ${branch}`); | |
}catch (err){ | |
console.error(err); | |
process.exit(1); | |
}; | |
}; | |
let branches = ` | |
origin/production-refresh/2021-04-14T07-08-58 | |
...[hundreds of branches]... | |
origin/production-refresh/2021-05-31T00-26-04 | |
`; | |
branches = branches.split('\n').map(s => s.trim()).filter(s => !!s); | |
(async () => { | |
await ex(`git switch master -f`); | |
await ex(`git reset --hard`) | |
await ex(`git reset origin/master --hard`); | |
for (const b of branches) { | |
await run(b.replace('origin/', '')); | |
} | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment