Skip to content

Instantly share code, notes, and snippets.

Last active July 12, 2017 17:42
What would you like to do?
git swap - swaps top two commits; git drop [revision] - nukes that revision (or HEAD); git hoist <revision> - rebases that revision to be the most recent commit, so you can tweak it
swap = "!GIT_SEQUENCE_EDITOR=\"sed -i '' -n 'h;1n;2p;g;p'\" git rebase -i HEAD~2"
drop = "!f() { GIT_SEQUENCE_EDITOR=\"sed -i '' '/^pick '$(git log -n 1 --pretty='%h' ${1:-HEAD})/d\" git rebase -i ${1:-HEAD}^^; }; f"
hoist = "!f() { GIT_SEQUENCE_EDITOR=\"git log -n 1 --pretty='pick %h' $1|~/bin/hoist-lines.pike\" git rebase -i $1^; }; f"
#! /usr/bin/env pike
// hoist-lines <filename> (un)hoists stdin-prefixed lines to the end in filename
int main(int argc, array argv) {
string prefix = - "\n";
string fn = argv[1];
array end = ({""});
array all = (Stdio.read_file(fn) / "\n") - end;
array hoist = Array.filter(all, has_prefix, prefix);
Stdio.write_file(fn, ((all - hoist) + hoist + end) * "\n");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment