LoginSignup
0
0

More than 3 years have passed since last update.

コミットIDからGithubのプルリクを探す

Last updated at Posted at 2020-04-18

何でこんなコードになってるんだろうと言う時、コミットメッセージを見てもよくわからなくてプルリクを見たい時よくあります。
そこでコミットIDからgithubのプルリクを開く方法を探しました。(対象はmacです)

  1. 以下のを~/.gitconfigに追加
[alias]
    find-merge = "!sh -c 'commit=$0 && branch=${1:-HEAD} && (git rev-list $commit..$branch --ancestry-path | cat -n; git rev-list $commit..$branch --first-parent | cat -n) | sort -k2 -s | uniq -f1 -d | sort -n | tail -1 | cut -f2'"
    show-merge = "!sh -c 'merge=$(git find-merge $0 $1) && [ -n \"$merge\" ] && git show $merge --oneline|xargs'"

上記により git show-merge [コミットID] で対象のコミットを含むマージコミットIDが出力されるようになります。    
2. hubをインストール(macはbrewでインストールできます)
$ brew install hub
3. ~/.bash_aliasに以下を追加

function open_github_pr(){
    git show-merge $1 | perl -nE 'system("hub browse -- pull/".$1) if/#(.*?)\sfrom/'
}
alias openpr=open_github_pr

a
4. aliasの反映

source ~/.bash_alias
5. 完了。以下を試してみてください。

openpr [任意のcommit id]
0
0
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
0
0