Created
October 10, 2023 05:58
-
-
Save chmouel/8450ed09ca42936009f0b9c27f4019f3 to your computer and use it in GitHub Desktop.
Drop a git commit from a branch in a middle non interactive
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
#!/usr/bin/env bash | |
# Copyright 2023 Chmouel Boudjnah <[email protected]> | |
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