LoginSignup
19
18

More than 5 years have passed since last update.

簡単にトピックブランチだけでinteractive rebaseする

Last updated at Posted at 2014-02-03

背景

プルリクエストを投げる前にトピックブランチのコミットを綺麗にしたい

問題

トピックブランチの根本のsha1が分からないのでいちいち調べないといけないので面倒です。

解法 1 - git-merge-base

こんな branch-root エイリアスを作ります。

~/.gitconfig
[alias]
  branch-root = merge-base master HEAD

あとはこのように実行すればトピックブランチだけでinteractive rebaseができる

$ git rebase -i $(git branch-root)

解説

git-merge-base は与えられたコミットの共通の祖先のsha1を出力してくれます。これを使うことで branch-root はトピックブランチの根本のsha1を標準出力します。

解法 2 - git-rev-list

~/.gitconfig
[alias]
  branch-first = !git rev-list master..HEAD | tail -n 1

こっちの場合は

$ git rebase -i $(branch-first)^

解説

git-rev-list は与えられたrevisionにマッチするsha1を出力してくれるので、その中で一番古いものを出力します。こうすることで branch-first はトピックブランチの一番最初のsha1を標準出力します。

19
18
2

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
19
18