Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
40
Help us understand the problem. What is going on with this article?
@uasi

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")" "$@"
40
Help us understand the problem. What is going on with this article?
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
uasi
レシピサービスを開発しています。 Qiita, Qiita:Team, Qiita Jobs を開発していました。趣味では Rust とシェルスクリプトをよく書きます。

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
40
Help us understand the problem. What is going on with this article?