設定ファイルがリポジトリに入っていて、開発環境で動かすときにはそのファイルが発効するので必要に応じて書き換えたいんだけどgitに(SourceTreeに)変更と認識されてしまいたくない、とかいう場面ってあります。
既に git 管理しているファイルをあえて無視したい - Qiita
この記事の通り、
- ローカル変更を無視する git update-index --assume-unchanged
- ローカルファイルをリポジトリ管理から切り離す git update-index --skip-worktree
というコマンドがGitには用意されています(前者と後者の違いは、リポジトリ側で変更があったときに実ファイルに反映されるかです。後者なら反映もされません)。
でも開発体制によってはわりと頻繁に使いそうなこの機能、SourceTreeに組み込んで右クリックからすぐ呼べるようにしてみましょう。
以下のカスタム操作の定義ファイルを、Windowsなら AppData\Local\Atlassian\SourceTree 以下の customactions.xml とマージしてください。
customactions.xml
<?xml version="1.0"?>
<ArrayOfCustomAction xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<CustomAction>
<Caption>ローカルで管理対象外に</Caption>
<OpenInSeparateWindow>false</OpenInSeparateWindow>
<ShowFullOutput>false</ShowFullOutput>
<Target>git</Target>
<Parameters>update-index --skip-worktree $FILE</Parameters>
</CustomAction>
<CustomAction>
<Caption>管理対象に戻す</Caption>
<OpenInSeparateWindow>false</OpenInSeparateWindow>
<ShowFullOutput>false</ShowFullOutput>
<Target>git</Target>
<Parameters>update-index --no-skip-worktree $FILE</Parameters>
</CustomAction>
<CustomAction>
<Caption>ローカル変更を無視</Caption>
<OpenInSeparateWindow>false</OpenInSeparateWindow>
<ShowFullOutput>false</ShowFullOutput>
<Target>git</Target>
<Parameters>update-index --assume-unchanged $FILE</Parameters>
</CustomAction>
<CustomAction>
<Caption>ローカル変更の無視を解除</Caption>
<OpenInSeparateWindow>false</OpenInSeparateWindow>
<ShowFullOutput>false</ShowFullOutput>
<Target>git</Target>
<Parameters>update-index --no-assume-unchanged $FILE</Parameters>
</CustomAction>
</ArrayOfCustomAction>