{"thread":{"id":"8634","subject":"git-diff-index -C problem","startedAt":"2007-06-18T05:48:41Z","lastAt":"2007-06-18T06:26:41Z","messageCount":2,"participants":["Govind Salinas","Shawn O. Pearce"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"45252","messageId":"69b0c0350706172248l6343e4c6yfd36ced8230a11ef@mail.gmail.com","threadId":"8634","inReplyTo":null,"subject":"git-diff-index -C problem","fromName":"Govind Salinas","fromEmail":"govindsalinas@gmail.com","sentAt":"2007-06-18T05:48:41Z","receivedAt":"2007-06-18T05:48:41Z","isPatch":false,"sender":{"key":"govindsalinas@gmail.com","avatar":null},"body":"I am writing a porcelain for git and I have been playing with\ngit-diff-index. I noticed that if i copy a file and git-add the copy\nit shows the file added, as i expect...\n\nBut then if i then say git-add on the original file, i expect that -C\nwould check that file to see if it was copied, it does not.  If i\ntouch the file, then git detects the copy, so git-add is not forcing\ngit to consider the file modified.\n\nI would be happy if there was a way that I could tell git that a file\nwas modified for this purpose.  Otherwise I will have to open/close a\nfile in which the user may be working, which I shouldn't do from my\napp (windows problem modifying open docs).  Maybe make \"git-add -f\" do\nthat?\n\nThanks,\nGovind.\n"},{"id":"45254","messageId":"20070618062641.GK18491@spearce.org","threadId":"8634","inReplyTo":"69b0c0350706172248l6343e4c6yfd36ced8230a11ef@mail.gmail.com","subject":"Re: git-diff-index -C problem","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2007-06-18T06:26:41Z","receivedAt":"2007-06-18T06:26:41Z","isPatch":false,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Govind Salinas <govindsalinas@gmail.com> wrote:\n> I am writing a porcelain for git and I have been playing with\n> git-diff-index. I noticed that if i copy a file and git-add the copy\n> it shows the file added, as i expect...\n> \n> But then if i then say git-add on the original file, i expect that -C\n> would check that file to see if it was copied, it does not.  If i\n> touch the file, then git detects the copy, so git-add is not forcing\n> git to consider the file modified.\n\nOddly enough if you add --find-copies-harder Git does actually\nfind the copy then, without needing to make the file stat-dirty\nin the index.\n\n  $ rm -rf foo;mkdir foo;cd foo;git init\n  Initialized empty Git repository in .git/\n\n  $ echo hello >a;git add a; git commit -m a\n  Created initial commit 9d2537b: a\n   1 files changed, 1 insertions(+), 0 deletions(-)\n   create mode 100644 a\n\n  $ cp a b;git add b\n  $ git diff-index --abbrev HEAD\n  :000000 100644 0000000... ce01362... A  b\n  $ git diff-index --abbrev -C HEAD\n  :000000 100644 0000000... ce01362... A  b\n  $ git diff-index --abbrev -C --find-copies-harder HEAD\n  :100644 100644 ce01362... ce01362... C100       a       b\n\n  $ touch a\n  $ git diff-index --abbrev -C HEAD\n  :100644 100644 ce01362... 0000000... M  a\n  :100644 100644 ce01362... ce01362... C100       a       b\n\nI *think* the reason this happens is because -C means to find a copy\namong the other modified files.  Because \"a\" was not modified (unless\nit is stat-dirty or otherwise modified) then \"b\" is not a copy of it.\n\nThe --find-copies-harder makes us also look at the unmodified files,\nand there we find the copy.\n\nIndeed, the documentation says exactly that:\n\n  --find-copies-harder::\n      For performance reasons, by default, `-C` option finds copies only\n      if the original file of the copy was modified in the same\n      changeset.  This flag makes the command\n      inspect unmodified files as candidates for the source of\n      copy.  This is a very expensive operation for large\n      projects, so use it with caution.  Giving more than one\n      `-C` option has the same effect.\n\nSo what you are seeing is actually as designed, and documented.\n\n-- \nShawn.\n"}]}