3

Say I have a file, myfile.txt. It has a paragraph of text in it, and I copy it to a new file, myfile2.txt.

If I git diff, it will show myfile2.txt as a new file. Okay. Now I replace every occurrence of "the" with "hello" and commit.

The problem I'm having is that after the commit happens, git diff will show all of myfile2.txt as a new file and it will not show me that "the" has been replaced by "hello" everywhere (because as far as it's concerned everything is a new change).

Even if I first commit and push myfile2.txt prior to editing so that the changes are evident, that's not a good solution. It is a problem because if I squash commits down to a feature and commit it, myfile2.txt shows up as a brand new file, whereas I would like to see that those replacements have been made.

Does git have a feature that allows me to track changes in a file that was copied from another, such that a git diff will show me only those modifications and not the added file as a whole?

S.L. Barth
  • 7,954
  • 71
  • 47
  • 62
Navin Aggrawal
  • 179
  • 1
  • 2
  • 10

2 Answers2

4

try git diff -M / git diff -C

J-16 SDiZ
  • 24,740
  • 3
  • 61
  • 82
0

I had a similar question recently about the issue of directory renames with similar advice.

There is also the --patience option to have a look at git-diff-patience.

Community
  • 1
  • 1
Philip Oakley
  • 11,745
  • 8
  • 42
  • 63