git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
POPol Online <info@pol-online.net>
Date
Nov 30, 2014, 01:30 UTC
Message-ID
<CAJxwDJzxUEd3czHpwDtKaERKDhvyCGOzGbKO4X9z44ugTJ2q4w@mail.gmail.com>
In-Reply-To
<CAGyf7-E_y8zRUKh5RWvAhPXzSgpnVab6e=e1v92rSVVxf+LNJg@mail.gmail.com>
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@atlassian.com> wrote:
Show 59 quoted lines
> 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@pol-online.net> 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@vger.kernel.org
>> More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous: Bryan TurnerNext: Bryan Turner
Message 3 of 12 in “git status / git diff -C not detecting file copy”
  1. Pol OnlineNov 30, 2014
  2. Bryan TurnerNov 30, 2014
  3. Pol OnlineNov 30, 2014
  4. Bryan TurnerNov 30, 2014
  5. Jeff KingDec 2, 2014
  6. Pol OnlineDec 2, 2014
  7. Junio C HamanoDec 2, 2014
  8. Jeff KingDec 2, 2014
  9. Junio C HamanoDec 3, 2014
  10. Bryan TurnerDec 2, 2014
  11. Jeff KingDec 2, 2014
  12. Junio C HamanoDec 3, 2014

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.