Skip to content

Instantly share code, notes, and snippets.

@chmouel
Created October 10, 2023 05:58
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 chmouel/8450ed09ca42936009f0b9c27f4019f3 to your computer and use it in GitHub Desktop.
Save chmouel/8450ed09ca42936009f0b9c27f4019f3 to your computer and use it in GitHub Desktop.
Drop a git commit from a branch in a middle non interactive
#!/usr/bin/env bash
# Copyright 2023 Chmouel Boudjnah <chmouel@chmouel.com>
set -eufo pipefail
commit=$(git log --graph --color=always \
--format="%C(auto)%h%d %s %C(black)%C(bold)%cr" "$@" |
env FZF_DEFAULT_OPTS="--bind=ctrl-d:preview-half-page-down,ctrl-u:preview-half-page-up,ctrl-j:preview-down,ctrl-k:preview-up" \
fzf --ansi -m --no-sort --reverse --tiebreak=index)
sha=$(echo "${commit}" | grep -o '[a-f0-9]\{7\}' | head -1)
[[ -z ${sha} ]] && exit 1
GIT_SEQUENCE_EDITOR="sed -i -re 's/^pick ${sha}/drop ${sha}/'" git rebase -i ${sha}~1
echo "${commit} has been dropped"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment