{"thread":{"id":"19705","subject":"Git confused when file is renamed/renamed+modified and result merged","startedAt":"2009-06-05T20:06:04Z","lastAt":"2009-06-05T20:06:04Z","messageCount":1,"participants":["Tomas Carnecky"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"115558","messageId":"B88C71A7-5EDB-4DAC-9288-E1C700C255DA@dbservice.com","threadId":"19705","inReplyTo":null,"subject":"Git confused when file is renamed/renamed+modified and result merged","fromName":"Tomas Carnecky","fromEmail":"tom@dbservice.com","sentAt":"2009-06-05T20:06:04Z","receivedAt":"2009-06-05T20:06:04Z","isPatch":false,"sender":{"key":"tom@dbservice.com","avatar":"https://gravatar.com/avatar/900a300bdd1a8bbe086008ad78210bbee2ad2803b7d50a5cba04c1e9404bd6d2?d=mp&s=160"},"body":"I was helping someone on IRC with merge problems and it boiled down to  \nthis. Git is confused when one branch renames a file while another  \nbranch renames the file in the same way and then modifies the file.  \nWhen merging the two branches git will indicate a conflict in the  \n'source' file (rename/delete) but not the 'destination' file and will  \nput the destination file from the first branch into the working tree,  \neven though the second branch has a file with the same name but  \nconflicting contents.\n\nGit commands that lead up to this situation, with interleaved  \ncomments. A usability suggestion is also included in the following  \ntranscript:\n\nbash-3.2$ git --version\ngit version 1.6.3.2.198.g6096d\nbash-3.2$ git init\nInitialized empty Git repository in /Users/tomc/gitest/.git/\nbash-3.2$ echo arst > file1\nbash-3.2$ git add file1\nbash-3.2$ git commit -m 'initial commit'\n[master (root-commit) fdad65c] initial commit\n  1 files changed, 1 insertions(+), 0 deletions(-)\n  create mode 100644 file1\nbash-3.2$ git branch new\n\n# branch master renames the file without modifying it\nbash-3.2$ git mv file1 file2\nbash-3.2$ git commit -m 'move file1 to file2'\n[master 053cc6f] move file1 to file2\n  1 files changed, 0 insertions(+), 0 deletions(-)\n  rename file1 => file2 (100%)\nbash-3.2$ git checkout new\nSwitched to branch 'new'\n\n# branch new moves the file while modifying it so heavily that git  \ndoesn't\n# recognize it as a rename anymore\nbash-3.2$ git rm file1\nrm 'file1'\nbash-3.2$ echo qwfp > file2\nbash-3.2$ git add file2\nbash-3.2$ git commit -m 'move file1 to file2, while heavily modifying  \nit'\n[new 4118625] rename file1 to file2, while heavily modifying it\n  2 files changed, 1 insertions(+), 1 deletions(-)\n  delete mode 100644 file1\n  create mode 100644 file2\n\n# merge new into master\nbash-3.2$ git checkout master\nSwitched to branch 'master'\nbash-3.2$ git merge new\n\n# Usability suggestion: Not clear to which file the 'deleted in new' is\n# referring to. Maybe change the message to:\n# CONFLICT in 'file1' (rename/delete): Renamed to file2 in HEAD,  \ndeleted in new.\nCONFLICT (rename/delete): Rename file1->file2 in HEAD and deleted in new\nAutomatic merge failed; fix conflicts and then commit the result.\n\n# as expected, there's a conflict in 'file1'. But 'file2' is silently  \naccepted\n# from the 'master' branch, even though the 'new' branch has a file  \nwith the\n# same name but different contents\nbash-3.2$ git show :2:file2\narst\nbash-3.2$ git show :3:file2\nfatal: ambiguous argument ':3:file2': unknown revision or path not in  \nthe working tree.\nUse '--' to separate paths from revisions\nbash-3.2$ git show new:file2\nqwfp\nbash-3.2$\n\ntom\n"}]}