2

In two test commits, wherein the first had only the operation git mv file moved_file, and the second only mv moved_file moved_again_file && git add -A moved_file moved_again_file, both appear as renames in git status before commit, but in git commit --verbose they show as new and removed files.

I'm expecting git diff-tree HEAD after each commit to show one R (rename) status but I keep getting two: an A and a D.

I'm trying to write a script that will perform actions based on file statuses but I can't properly plan for R (or C) statuses if they always show up as add/delete.

Git is version 1.8.3.1, if that makes a difference.

Walf
  • 8,535
  • 2
  • 44
  • 59

1 Answers1

4

The git diff-tree command is a plumbing command, not a porcelain command, so that it has predictable behavior.

One of these is that rename detection is off unless explicitly turned on. Contrast this with, e.g., git diff, which is a porcelain command and therefore sets rename detection based on your personal configuration for diff.renames.

To get rename detection turned on, add -M or --find-renames (and their optional thresholds). Use -C or --find-copies (with their optional thresholds) to find copies; add --find-copies-harder if desired.

Walf
  • 8,535
  • 2
  • 44
  • 59
torek
  • 448,244
  • 59
  • 642
  • 775
  • I know it's a plumbing command, that's why I'm using it for input. I just didn't know those options had to be enabled as the man page has nothing about that in the `RAW OUTPUT FORMAT` section, nor more about each option outside of their descriptions. – Walf Jul 18 '17 at 01:23
  • 1
    Yes, the documentation ... well, not to put too fine a point on it, sucks :-) It's particularly bad in that a lot of the diff-generating commands have different default behaviors in some of the trickier corner cases, but there is zero mention of this anywhere. – torek Jul 18 '17 at 05:58