Skip to content

Instantly share code, notes, and snippets.

@johan
Last active July 12, 2017 17:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johan/22a8c00fe14b742b337e5b56c56862ed to your computer and use it in GitHub Desktop.
Save johan/22a8c00fe14b742b337e5b56c56862ed to your computer and use it in GitHub Desktop.
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
[alias]
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 = Stdio.stdin.read() - "\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