LoginSignup
35
35

More than 5 years have passed since last update.

Gitローカル変更の無視をSourceTreeからも

Last updated at Posted at 2014-11-04

設定ファイルがリポジトリに入っていて、開発環境で動かすときにはそのファイルが発効するので必要に応じて書き換えたいんだけど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>
35
35
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
35
35