Re: git status / git diff -C not detecting file copy

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Pol,

It's the same set of limitations. Git does not track renames or copies
as such. It uses heuristics to compute a similarity index and then
decide. All the tree stores for your copy is a file add, and that's
the status you're seeing. I don't think there is any way to turn on
aggressive copy detection for git status. However, before you run git
commit, you could run git diff --find-copies-harder --cached instead
and it should show the copy.

I'll let someone a little more intimately familiar with the internals
of git status comment on why the documentation for that mentions
copies.

Hope this helps,
Bryan Turner

On Sun, Nov 30, 2014 at 12:30 PM, Pol Online <info@xxxxxxxxxxxxxx> wrote:
> Hi Bryan,
>
> OK that explains the behavior of git diff, but what about git status?
> The doc implies it should be able to detect copies in the index /
> staging area since it has a "C" state.
>
> - Pol
>
> On Sun, Nov 30, 2014 at 10:03 AM, Bryan Turner <bturner@xxxxxxxxxxxxx> wrote:
>> Pol,
>>
>> By default, -C only finds copies when the source file was also
>> modified in the same commit. Since you did not modify hello.txt in the
>> same commit where you copied it to copied.txt, it will not be
>> considered.
>>
>> If you pass -C -C (twice), or use --find-copies-harder, Git will
>> consider all files in the repository. Note that this can be slower,
>> which is the reason why it's not the default.
>>
>> The documentation for git diff describes the -C (--find-copies) and
>> --find-copies-harder flags and their limitations.
>>
>> Hope this helps,
>> Bryan Turner
>>
>> On Sun, Nov 30, 2014 at 11:35 AM, Pol Online <info@xxxxxxxxxxxxxx> wrote:
>>> Hi,
>>>
>>> The documentation for git status at http://git-scm.com/docs/git-status
>>> implies that it should be able to detect both renames and copies (with
>>> the R and C states). The command git diff -C should do it as well.
>>>
>>> However I can't get either to detect copies in this simple test case -
>>> what is happening?
>>>
>>>
>>> mkdir test
>>> cd test/
>>> git init
>>> echo 'Hello World!' > hello.txt
>>> echo 'Goodbye World!' > goodbye.txt
>>> git add -A
>>> git commit -m "Initial commit"
>>>
>>> cp hello.txt copied.txt
>>> mv goodbye.txt moved.txt
>>> git add -A
>>>
>>> $ git status --short
>>> A  copied.txt  <------------ NO COPY DETECTED
>>> R  goodbye.txt -> moved.txt
>>>
>>> $ git diff -M -C --summary --cached
>>>  create mode 100644 copied.txt  <------------ NO COPY DETECTED
>>>  rename goodbye.txt => moved.txt (100%)
>>>
>>> $ git commit -m Test
>>> $ git diff -M -C --summary HEAD~
>>>   create mode 100644 copied.txt  <------------ NO COPY DETECTED
>>>   rename goodbye.txt => moved.txt (100%)
>>>
>>>
>>> -Pol
>>> --
>>> To unsubscribe from this list: send the line "unsubscribe git" in
>>> the body of a message to majordomo@xxxxxxxxxxxxxxx
>>> More majordomo info at  http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]