LoginSignup
1
4

More than 5 years have passed since last update.

sourcetree で色々出来るように設定をする

Last updated at Posted at 2017-06-07

ブランチの名前を自動挿入するgit hooksを利用する

ソース

.git/hooks/prepare-commit-msg

#!/usr/bin/env ruby

#今いるブランチ名を取得
current_branch = `git branch | grep '*'`.chomp.sub('* ', '')

commit_msgs = File.readlines(ARGV[0])
open(ARGV[0], 'w') {|file|
    file.print "#{current_branch}:"
    file.puts commit_msgs
}

コマンド

chmod +x .git/hooks/prepare-commit-msg

動く権限を与える

gitの差分をzipファイルで取得する

export_diff_zip.sh
任意の場所に作成

#!/bin/sh
if [ "$2" = "" ]; then
    git archive --format=zip --prefix=archive/ HEAD `git diff --name-only HEAD $1` -o archive.zip
else
    git archive --format=zip --prefix=archive/ $1 `git diff --name-only $1 $2` -o archive.zip
fi

コマンドで権限を与える

chmod +x export_diff_zip.sh

ソースツリー側の設定

Macの場合 メニューから「SourceTree」→「環境設定」→「カスタムアクション」タブ→「追加」ボタンをクリック

  • 「メニュー表示名」: メニューに表示したい名前を設定します。今回は「指定された差分をzipで書き出す」と指定します。
  • 「実行するスクリプト」: 実行するスクリプトファイルのパスを指定します。「1.バッチファイルの作成」で用意したバッチファイルを指定します。
  • 「パラメータ」: 実行するスクリプトに送る引数を決めます。今回は「$SHA」のみを使用するので「$SHA」を記入します。

使い方

  • 一つコミットを左クリックで選択する
  • Ctrl( MacはCommand )キーを押しながら左クリックでもう1箇所(計2箇所)コミットを選択する
  • 2箇所コミットを選択したまま右クリックをする
  • 出てくるメニュー一番下の「カスタム操作」から「指定された差分をzipで書き出す」を選ぶ

引用
https://ics.media/entry/4475

これだとたまにうまく動作しない時があるらしい。

その時は下記を利用する
http://qiita.com/lab3-34/items/e69ab8d0c51c9b64fe02

1
4
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
1
4