LoginSignup
34
31

More than 5 years have passed since last update.

tigを使って簡単にfixupやsquashコミットを作る

Last updated at Posted at 2015-12-10

少しずつ市民権を得てきた感のある interactive git rebase 時の autosquash オプションですが、いくら git commit で --fixup や --squash で自動生成できると言っても、そもそも対象となるコミットを選択するのがめんどくさいという問題があると思います。

最近だと peco を使ってコミットを絞り込むなどの方法があるかも知れませんが、すでに tig を使っているならtigを使うのが楽です。

~/.gitconfig
[tig "bind"]
diff = F ?!git commit --fixup %(commit)
diff = S ?!git commit --squash %(commit)
main = F ?!git commit --fixup %(commit)
main = S ?!git commit --squash %(commit)

git config にこんな感じで tig のキーバインディングを追加します。これがあると、 main-view と diff-view で shift+s で現在選択されているコミットに対して --squash が実行されます。 shift+f なら --fixup です。

ちなみに ?!git! は外部コマンドを実行するという意味です。 ? があるとそのコマンドを実行する前に本当にそれを実行するのか聞いてくれるようになります。今回のように何かしらを変更するコマンドを実行する場合は付けておくといいと思います。

その他のキーバインディング

せっかくなので設定している他のキーバインディングも紹介します

blob/commit/tree を github で開く

~/.gitconfig
[tig "bind"]
blob = B @hub browse -- tree/%(commit)/%(file)
diff = B @hub browse -- commit/%(commit)
tree = B @hub browse -- tree/%(commit)/%(directory)

これを設定した状態で blob/diff/tree-view で shift+b を押すと、ブラウザが起動して github 上で対応するページが表示されます。使用するには hub が必要です。

@hub@ があるとコンソール出力が表示されなくなります。

上下に素早く移動する

~.gitconfig
[tig "bind"]
diff = <Ctrl-n> :/^@@
diff = <Ctrl-p> :?^@@
log = <Ctrl-n> :/^commit
log = <Ctrl-p> :?^commit
stage = <Ctrl-n> :/^@@
stage = <Ctrl-p> :?^@@

diff/log/stage-veiew で ctrl-n ctrl-p を押した時に、ファイル単位もしくはコミット単位で上下移動してくれるようになります。jkで行単位の上下移動ができるので、これと組み合わせると好きな場所に移動するのが結構楽になります。

34
31
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
34
31