Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I force git diff to treat a file as a copy?

The diff functionality in git has "copy detection"--if it detects that a new file is actually a (possibly modified) copy of an existing file, the diff output shows the differences between the source file and the new file rather than just a bunch of additions from a blank file to the new file.

As far as I can tell, git diff uses some heuristics to detect this situation. Unfortunately it is not detecting a particular new file as a copy of another file because I guess it has changed too much. I'd still like to view the diff as though it were a copy. Is there a way to inform git diff that the new file is a copy of another so that it will do this for me?

like image 916
nohat Avatar asked Apr 20 '09 20:04

nohat


People also ask

Does git only store diffs?

No, commit objects in git don't contain diffs - instead, each commit object contains a hash of the tree, which recursively and completely defines the content of the source tree at that commit.

What does diff do in git?

Comparing changes with git diff Diffing is a function that takes two input data sets and outputs the changes between them. git diff is a multi-use Git command that when executed runs a diff function on Git data sources. These data sources can be commits, branches, files and more.

Can git diff binary files?

Any binary format can be diffed with git, as long as there's a tool which converts the binary format to plain text. One just needs to add the conversion handlers and attributes in the same way.

Does git diff show deleted files?

You can use git diff --name-status, that will show you files that where added, modified and deleted.


1 Answers

git diff (at least my version 1.5.6 does) comes with the switch --find-copies-harder, which does more cpu-intensive copy detection than the regular -C does.

like image 177
antifuchs Avatar answered Oct 18 '22 17:10

antifuchs