Skip to content

Instantly share code, notes, and snippets.

@AnrDaemon
Created July 22, 2024 19:57
Show Gist options
  • Save AnrDaemon/318d233f9fea65e80159f9ebd774d91b to your computer and use it in GitHub Desktop.
Save AnrDaemon/318d233f9fea65e80159f9ebd774d91b to your computer and use it in GitHub Desktop.
Git rebase-editor with files list

git config --global sequence.editor rebase-editor.sh

#!/bin/sh
_tmp="$(mktemp --tmpdir -- git-rebase-todo.XXXXXX )"
_editor="$(git config core.editor)"
cp "$1" "$_tmp"
{
while read -r _ cid header; do
if [ "$_" = "pick" ]; then
printf "pick %s %s\n" "$cid" "$header"
git diff --name-only -z "$cid^!" | xargs -0 printf "# %s\n" #sed -Ee '/^$/d; s/^/# /;'
else
echo "$_${cid:+ $cid}${header:+ $header}"
fi
done
} > "$1" < "$_tmp"
rm "$_tmp"
"${_editor?-${GIT_EDITOR:?Please define GIT_EDITOR env.var.}}" "$1"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment