Help us understand the problem. What is going on with this article?

git commit --fixup で fixup する対象を peco/fzf で選べるスクリプト書いた

More than 1 year has passed since last update.

fixup-interactive.gif

git commit --fixup が何かについてはgit commit --fixup とは何か - 詩と創作・思索のひろばを読んでもらうとして、 fixup を適用したいコミットをいちいち git log で調べるのが面倒なのでインタラクティブに選べるようにした。

以下のスクリプトをパスの通ったディレクトリに置くと git fixup が使えるようになる。適当な変更を git add して git fixup を実行すると、その変更を fixup として適用したいコミットを peco や fzf で選べる。

git-fixup
#!/bin/bash

FILTER=${FILTER:-peco}
MAX_LOG_COUNT=${MAX_LOG_COUNT:-30}

if git diff --cached --quiet; then
    commits="No staged changes. Use git add -p to add them."
    ret=1
else
    commits=$(git log --oneline -n "$MAX_LOG_COUNT")
    ret=$?
fi

if [[ "$ret" != 0 ]]; then
    headline=$(head -n1 <<< "$commits")
    if [[ "$headline" = "No staged changes. Use git add -p to add them." ]]; then
        echo "$headline" >&2
    fi
    exit "$ret"
fi

line=$("$FILTER" <<< "$commits")
[[ "$?" = 0 && "$line" != "" ]] || exit "$?"

git commit --fixup "$(awk '{print $1}' <<< "$line")" "$@"
uasi
Qiita, Qiita:Team, Qiita Jobs を開発していました。趣味では Rust とシェルスクリプトをよく書きます。
http://uasi.hatenablog.com/
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした