Last active
April 4, 2018 16:03
-
-
Save jirutka/b071a577c494a7e334e536ce7f9244b5 to your computer and use it in GitHub Desktop.
git edit – start interactive rebase to edit the specified commit.
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
#!/bin/sh | |
# vim: set ts=4: | |
set -e | |
if [ $# -eq 0 ] || [ "$1" = '-h' ]; then | |
cat >&2 <<-EOF | |
Usage: git edit <tree-ish> | |
git edit [-h] | |
Start interactive rebase to edit the specified commit. | |
EOF | |
exit 1 | |
fi | |
if [ -n "$GIT_EDIT_COMMIT" ]; then | |
# $1 is path of the message showed by "git rebase -i"; we just edit it for | |
# the user. | |
sed -E "s/^pick ($GIT_EDIT_COMMIT.*)/edit \1/" "$1" > /tmp/git.$$ | |
mv /tmp/git.$$ "$1" | |
else | |
GIT_EDIT_COMMIT="$(git rev-parse --short $1)" \ | |
|| { echo "fatal: bad revision '$1'"; exit 128; } | |
export GIT_EDIT_COMMIT | |
# Start interactive rebase from the parent of the specified commit | |
# and use this script as EDITOR. | |
GIT_EDITOR="$0" git rebase -i "$GIT_EDIT_COMMIT"~1 | |
fi |
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
#!/bin/sh | |
# vim: set ts=4: | |
set -e | |
if [ $# -eq 0 ] || [ "$1" = '-h' ]; then | |
cat >&2 <<-EOF | |
Usage: git reword <tree-ish> | |
git reword [-h] | |
Start interactive rebase to reword the specified commit. | |
EOF | |
exit 1 | |
fi | |
# This variable is set when git executes this script to edit the actual commit | |
# message. Unsetting GIT_EDITOR after 2nd step didn't prevent it, so we must | |
# use this hack. | |
if [ -n "$GIT_INDEX_FILE" ]; then | |
exec ${EDITOR:-vim} "$1" | |
elif [ -n "$GIT_EDIT_COMMIT" ]; then | |
# $1 is path of the message showed by "git rebase -i"; we just edit it for | |
# the user. | |
sed -E "s/^pick ($GIT_EDIT_COMMIT.*)/reword \1/" "$1" > /tmp/git.$$ | |
mv /tmp/git.$$ "$1" | |
else | |
GIT_EDIT_COMMIT="$(git rev-parse --short $1)" \ | |
|| { echo "fatal: bad revision '$1'"; exit 128; } | |
export GIT_EDIT_COMMIT | |
# Start interactive rebase from the parent of the specified commit | |
# and use this script as EDITOR. | |
GIT_EDITOR="$0" git rebase -i "$GIT_EDIT_COMMIT"~1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment