Permalink
Browse files

Add a `cherry-drop` alias

  • Loading branch information...
JustinAiken committed Sep 28, 2017
1 parent cd71766 commit 043dfaa05867059b1d05517992614cc5ad557dcc
Showing with 26 additions and 0 deletions.
  1. +1 −0 .gitconfig
  2. +25 −0 .githelpers
View
@@ -50,6 +50,7 @@
undo-commit = reset --soft HEAD~1
fubard-local = !CURRENT=$(git rev-parse --abbrev-ref HEAD) && git reset --hard origin/$(git rev-parse --abbrev-ref HEAD)
inject = "!f() { set -e; HASH=`git show $1 --pretty=format:\"%H\" -q`; shift; git commit -m \"fixup! $HASH\" $*; [ -n \"$(git diff-files)\" ] && git stash && DIRTY=1; git rebase $HASH^^ -i --autosquash; [ -n \"$DIRTY\" ] && git stash pop;}; f"
cherry-drop = "!. ~/.githelpers && cherry_drop"
whatsgoinon = for-each-ref --count=10 --sort=-committerdate refs/heads/ --format="%(refname:short)"
obeyyourmaster = "!git fetch; git reset --hard origin/master"
keepup = "!git fetch; git rebase origin/master -S"
View
@@ -29,3 +29,28 @@ pretty_git_log() {
# / *********************************** Gary Bernhardt's pretty log ***********************************
cherry_drop() {
set -e
REF_TO_DROP=`git show $1 --pretty=format:%H -q`
HEAD=`git show HEAD --pretty=format:%H -q`
shift
# Stash changes if they exist
if ! git diff-index --quiet HEAD --; then
git stash && DIRTY=1
fi
if [[ $REF_TO_DROP == $HEAD ]]; then
# Easy way to undo a commit:
git reset --hard HEAD
else
# Rebase the commit out:
git rebase --keep-empty --onto $REF_TO_DROP~1 $REF_TO_DROP
fi
# Unstash changes if they were stashed:
[ -n "$DIRTY" ] && git stash pop
# Great success:
exit 0
}

0 comments on commit 043dfaa

Please sign in to comment.