{"thread":{"id":"14183","subject":"possible 'git cp'/how does git detect copies","startedAt":"2008-06-27T12:40:22Z","lastAt":"2008-06-27T13:16:41Z","messageCount":6,"participants":["Mircea Bardac","Santi Béjar","Pierre Habouzit","Johannes Sixt","Miklos Vajna"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"81383","messageId":"4864DFB6.3050204@mircea.bardac.net","threadId":"14183","inReplyTo":null,"subject":"possible 'git cp'/how does git detect copies","fromName":"Mircea Bardac","fromEmail":"dev@mircea.bardac.net","sentAt":"2008-06-27T12:40:22Z","receivedAt":"2008-06-27T12:40:22Z","isPatch":false,"sender":{"key":"dev@mircea.bardac.net","avatar":"https://gravatar.com/avatar/9cf887bf86f677aafb60f450e5898c0342283ebf3633c9bdbec1233256f2510f?d=mp&s=160"},"body":"I was looking today at duplicating a file but, I soon realized that \nthere is no 'git cp' command (this was the \"deductive approach to git \ncommands\", starting from git mv/rm/...). How does \"git diff -C\" detect \ncopies (-C is used for this, according to the documentation)?\n\nOn a very simple test, I couldn't see this working. I just copied one \nfile, added it, committed the change, ran \"git diff -C HEAD^!\". There is \nno place saying that it's contents is copied from some other file (both \nfiles are in the repository now).\n\n\"git blame -C new_copied_file\" also doesn't show the commits for the \noriginal file.\n\nThis is all with 1.5.6.1.\n\nI am probably missing something here... but I can't produce an example \nof copied contents that actually works. Any hint would be appreciated.\n\nI found this older thread [1] on \"git cp\" but the discussion appears to \nhave stalled at some point. If there is indeed no use of a \"git cp\" \ncommand, I would like at least some info on how content copies are being \ndetected, since I haven't seen this working.\n\n[1] http://kerneltrap.org/mailarchive/git/2008/2/3/705424\n\n\nMany thanks,\nMircea\n\n--\nhttp://mircea.bardac.net\n"},{"id":"81385","messageId":"8aa486160806270557w20ce622co1099bceec7bc90f9@mail.gmail.com","threadId":"14183","inReplyTo":"4864DFB6.3050204@mircea.bardac.net","subject":"Re: possible 'git cp'/how does git detect copies","fromName":"Santi Béjar","fromEmail":"sbejar@gmail.com","sentAt":"2008-06-27T12:57:13Z","receivedAt":"2008-06-27T12:57:13Z","isPatch":false,"sender":{"key":"santi@agolina.net","avatar":null},"body":"On Fri, Jun 27, 2008 at 14:40, Mircea Bardac <dev@mircea.bardac.net> wrote:\n> I was looking today at duplicating a file but, I soon realized that there is\n> no 'git cp' command (this was the \"deductive approach to git commands\",\n> starting from git mv/rm/...). How does \"git diff -C\" detect copies (-C is\n> used for this, according to the documentation)?\n\nDid you followed the \"See also −−find−copies−harder.\"?\n\n>From the man page\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\n\n>\n> On a very simple test, I couldn't see this working. I just copied one file,\n> added it, committed the change, ran \"git diff -C HEAD^!\". There is no place\n> saying that it's contents is copied from some other file (both files are in\n> the repository now).\n>\n> \"git blame -C new_copied_file\" also doesn't show the commits for the\n> original file.\n\ngit blame -C -C new_copied_file\n"},{"id":"81388","messageId":"20080627130006.GC17898@artemis.madism.org","threadId":"14183","inReplyTo":"4864DFB6.3050204@mircea.bardac.net","subject":"Re: possible 'git cp'/how does git detect copies","fromName":"Pierre Habouzit","fromEmail":"madcoder@debian.org","sentAt":"2008-06-27T13:00:06Z","receivedAt":"2008-06-27T13:00:06Z","isPatch":false,"sender":{"key":"madcoder@debian.org","avatar":"https://avatars.githubusercontent.com/u/44708?v=4"},"body":"On Fri, Jun 27, 2008 at 12:40:22PM +0000, Mircea Bardac wrote:\n> I was looking today at duplicating a file but, I soon realized that there \n> is no 'git cp' command (this was the \"deductive approach to git \n> commands\", starting from git mv/rm/...). How does \"git diff -C\" detect \n> copies (-C is used for this, according to the documentation)?\n\n  By comparing if files (blobs) are alike. It has some heuristics to\nguess which files have good changes to be copies or renames of each\nothers. But it recomputes the information each time.\n\n> On a very simple test, I couldn't see this working. I just copied one \n> file, added it, committed the change, ran \"git diff -C HEAD^!\". There is \n> no place saying that it's contents is copied from some other file (both \n> files are in the repository now).\n> \n> \"git blame -C new_copied_file\" also doesn't show the commits for the \n> original file.\n\n  You probably want to use -C -C -M actually.\n\n> I found this older thread [1] on \"git cp\" but the discussion appears to \n> have stalled at some point. If there is indeed no use of a \"git cp\" \n> command, I would like at least some info on how content copies are being \n> detected, since I haven't seen this working.\n\n  If you really need it, you can and an alias alias.cp=!cp and be done\nwith it ;P\n\n-- \n·O·  Pierre Habouzit\n··O                                                madcoder@debian.org\nOOO                                                http://www.madism.org\n"},{"id":"81394","messageId":"4864E58E.4090000@viscovery.net","threadId":"14183","inReplyTo":"4864DFB6.3050204@mircea.bardac.net","subject":"Re: possible 'git cp'/how does git detect copies","fromName":"Johannes Sixt","fromEmail":"j.sixt@viscovery.net","sentAt":"2008-06-27T13:05:18Z","receivedAt":"2008-06-27T13:05:18Z","isPatch":false,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Mircea Bardac schrieb:\n> I was looking today at duplicating a file but, I soon realized that\n> there is no 'git cp' command (this was the \"deductive approach to git\n> commands\", starting from git mv/rm/...). How does \"git diff -C\" detect\n> copies (-C is used for this, according to the documentation)?\n> \n> On a very simple test, I couldn't see this working. I just copied one\n> file, added it, committed the change, ran \"git diff -C HEAD^!\". There is\n> no place saying that it's contents is copied from some other file (both\n> files are in the repository now).\n> \n> \"git blame -C new_copied_file\" also doesn't show the commits for the\n> original file.\n> \n> This is all with 1.5.6.1.\n> \n> I am probably missing something here... but I can't produce an example\n> of copied contents that actually works. Any hint would be appreciated.\n\nIf you modify the original file in the same commit, then you should see\nthe copy. Otherwise, you can try git diff -C -C aka --find-copies-harder.\n\n-- Hannes\n"},{"id":"81395","messageId":"20080627130945.GN29404@genesis.frugalware.org","threadId":"14183","inReplyTo":"20080627130006.GC17898@artemis.madism.org","subject":"Re: possible 'git cp'/how does git detect copies","fromName":"Miklos Vajna","fromEmail":"vmiklos@frugalware.org","sentAt":"2008-06-27T13:09:45Z","receivedAt":"2008-06-27T13:09:45Z","isPatch":false,"sender":{"key":"vmiklos@frugalware.org","avatar":"https://gravatar.com/avatar/401c1cbbb3a5d13e650c691a2c71d6fd0b80df1a01bc74d9f1972675dd58f2bd?d=mp&s=160"},"body":"On Fri, Jun 27, 2008 at 03:00:06PM +0200, Pierre Habouzit <madcoder@debian.org> wrote:\n>   If you really need it, you can and an alias alias.cp=!cp and be done\n> with it ;P\n\nActually that's not that easy. git-mv moves untracked files and adds\ntracked files to the index as well. So such a git-cp would have to copy\ntracked and untracked files, and add tracked files to the index.\n\nI did it in the past:\n\nhttp://thread.gmane.org/gmane.comp.version-control.git/72388/focus=73347\n\nbut then we agreed about it's better not encouraging copy-and-paste.\n"},{"id":"81397","messageId":"4864E839.7000204@mircea.bardac.net","threadId":"14183","inReplyTo":"8aa486160806270557w20ce622co1099bceec7bc90f9@mail.gmail.com","subject":"Re: possible 'git cp'/how does git detect copies","fromName":"Mircea Bardac","fromEmail":"dev@mircea.bardac.net","sentAt":"2008-06-27T13:16:41Z","receivedAt":"2008-06-27T13:16:41Z","isPatch":false,"sender":{"key":"dev@mircea.bardac.net","avatar":"https://gravatar.com/avatar/9cf887bf86f677aafb60f450e5898c0342283ebf3633c9bdbec1233256f2510f?d=mp&s=160"},"body":"Hi,\n\nSanti Béjar wrote:\n> On Fri, Jun 27, 2008 at 14:40, Mircea Bardac <dev@mircea.bardac.net> wrote:\n>> I was looking today at duplicating a file but, I soon realized that there is\n>> no 'git cp' command (this was the \"deductive approach to git commands\",\n>> starting from git mv/rm/...). How does \"git diff -C\" detect copies (-C is\n>> used for this, according to the documentation)?\n> \n> Did you followed the \"See also −−find−copies−harder.\"?\n\nI knew this from before but for some reason I forgot about it when I \ntried it now. The documentation for \"git diff -C\" is a bit misleading. I \nhave originally tested on git 1.5.2.something and the documentation for \n-C didn't point to --find-copies-harder. I've quickly installed 1.5.6.1 \nto test the behavior but not the man pages.\n\nLooking over the online docs for 1.5.6.1, it appears that there is now a \nreference to --find-copies-harder.\n\nEven so, saying just that \"Detect copies as well as renames.\" is not \nenough, as it assumes that there is no restriction on the detection process.\n\n From --find-copies-harder\n\"For performance reasons, by default, -C option finds copies only if the \noriginal file of the copy was modified in the same changeset.\" should be \nmoved to -C.\n\n>> On a very simple test, I couldn't see this working. I just copied one file,\n>> added it, committed the change, ran \"git diff -C HEAD^!\". There is no place\n>> saying that it's contents is copied from some other file (both files are in\n>> the repository now).\n>>\n>> \"git blame -C new_copied_file\" also doesn't show the commits for the\n>> original file.\n> \n> git blame -C -C new_copied_file\n\nAh, duplicating the parameter. Looking better over these options I have \nnoticed that --find-copies-harder for \"git diff\" can also be replaced \nwith an extra -C. A little bit of consistency would help: either\n\"-C -C\", either \"--find-copies-harder\" in both git blame/diff. Removing \nfrom the documentation the deprecated version but keeping the \nimplementation for backwards compatibility might be a solution.\n\n\nMany thanks,\nMircea\n\nP.S. I know that patches are encouraged and technically it's pretty \nsimple to create a documentation patch, but I have not yet formed myself \na workflow for sending patches via Git to a maillist (this is a pending \ntask for me)\n\n--\nhttp://mircea.bardac.net\n"}]}