LoginSignup
12
10

More than 5 years have passed since last update.

pecoでgitのコミットハッシュを2つ選択してdiffを確認する

Posted at

.bashrcなり.zshrcなりに下記の関数を用意する
setopt ksharraysはzshの場合のみ記述する(zshの配列インデックスはデフォルトだと1ベースなので0ベースに変更する為のオプションがksharrays

function git-pdi() {
  setopt ksharrays  # 0 base array index for zsh
  HASHES=($(git log --pretty="format:%ad %h (%an): %s" --date=iso | peco | awk '{print $4}'))
  if [ ${#HASHES[@]} -eq 2 ]
  then
    git diff ${HASHES[1]}..${HASHES[0]}
  else
    echo "selected commit count must be 2, but ${#HASHES[@]}"
  fi
}

git-pdiを実行すると、pecoを起動し行単位でコミットの概要が表示されるので、Ctrl+Spaceで対象コミットを2つ選択してEnter
2つ目に選択したコミット → 1つ目に選択したコミット、という比較結果が表示される

git-pdi.gif

12
10
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
12
10