nulltokenの回答を使用して、コマンドラインからGitHubの2つのコミット間の差分を取得するための簡単な便利なスクリプトをまとめました。
完全なスクリプトは要点にありますが、ここに良い点があります。
# Parse the following patterns for repo urls to get the github repo url
# https://github.com/owner/repo-name.git
# git@github.com:owner/repo-name.git
BASE_URL="https://github.com/""$(git config --get remote.origin.url | sed 's/.*github\.com[/:]\(.*\).git/\1/')""/compare"
if [[ "$#" -eq 1 ]]; then
if [[ "$1" =~ .*\.\..* ]]; then
# Handle "git hubdiff fromcommit..tocommit"
open "${BASE_URL}/$(git rev-parse "${1/\.\.*/}")...$(git rev-parse ${1/*\.\./})"
else
# Handle "git hubdiff fromcommit"
open "${BASE_URL}/$(git rev-parse "$1")...$(git rev-parse HEAD)"
fi
elif [[ "$#" -eq 2 ]]; then
# Handle "git hubdiff fromcommit tocommit"
open "${BASE_URL}/$(git rev-parse "$1")...$(git rev-parse "$2")"
fi
引数として、ブランチ、コミット、およびで解決できるその他すべてのものを受け入れますgit rev-parse
。私はopen
、ウェブページを開くためにmacOSでのみ機能するを使用しました。そのため、別の環境を使用している場合は、それを微調整する必要があります。
nulltokenの回答と同様に、差分内の1つのファイルを指すには、ファイルのタイトルをクリックしてアンカー文字列をURLバーに表示し、コピーする必要があります。