LoginSignup
0
0

More than 1 year has passed since last update.

gitの差分について

Posted at

今まで、svnを使ってプログラムを管理していたのですが、開発したり、検証をしていくときにgitを使うと、検証段階のファイルを管理したり、以前の環境に戻したりするときにとても便利なことを知りました。gitのdiff確認について使ってみてよかったものをまとめてみたいと思います。

git diff

git diffコマンドは、変更前後の変更点を上下で出力してくれるので、小規模の変更は、git diffで確認しています。

// ワーキングエリアでの比較
$ git diff

// ファイルのみ
$ git diff --name-only

// ステージング上での比較
$ git diff --cached

// commitした者同士
$ git diff 変更前のSHA..変更後のSHA

git difftool

git上でデフォルトで使用するdiff toolを設定して、そのtoolを使用して差分を確認します。使用するtoolの設定は、.gitconfigに記述し、使用します。私は、windowsを使用しているので、winmergeをdiff toolとして、使用しています。workingエリアに置かれているファイルを確認するときに使用しています。設定方法は、こちらの記事に書いておきました。
winmergeをして変更したディレクトリとファイルの差分を表示し、差分を横並びに表示してくれるので、見るのが簡単で便利です。

$ git difftool -h
usage: git difftool [<options>] [<commit> [<commit>]] [--] [<path>...]

    -g, --gui             use `diff.guitool` instead of `diff.tool`
    -d, --dir-diff        perform a full-directory diff
    -y, --no-prompt       do not prompt before launching a diff tool
    --symlinks            use symlinks in dir-diff mode
    -t, --tool <tool>     use the specified diff tool
    --tool-help           print a list of diff tools that may be used with `--tool`
    --trust-exit-code     make 'git-difftool' exit when an invoked diff tool returns a non-zero exit code
    -x, --extcmd <command>
                          specify a custom command for viewing diffs
    --no-index            passed to `diff`
0
0
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
0
0