{"thread":{"id":"18043","subject":"Problems rebasing branch after renaming files","startedAt":"2009-02-27T08:55:29Z","lastAt":"2009-02-27T10:55:31Z","messageCount":2,"participants":["Salvatore Iovene","Jakub Narebski"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"106412","messageId":"c64207c00902270055q57442e2dmd81c197419dda71a@mail.gmail.com","threadId":"18043","inReplyTo":null,"subject":"Problems rebasing branch after renaming files","fromName":"Salvatore Iovene","fromEmail":"salvatore.iovene@googlemail.com","sentAt":"2009-02-27T08:55:29Z","receivedAt":"2009-02-27T08:55:29Z","isPatch":false,"sender":{"key":"salvatore.iovene@googlemail.com","avatar":null},"body":"Hi list,\nI ran into a problem, and I'm unsure it's a git bug or a misuse of mine.\n\nHere's the scenario:\n\n1) Have the master branch and a branch called A\n\nmaster\n|\n|----- A\n\n2) Work more in master\n\nmaster\n|\n|----- A\n|\n|\n\n3) Create branch B and work on it. In this branch, rename a directory\ncontaining source files with git-mv\n\nmaster\n|\n|----- A\n|\n|----- B\n\n4) Merge B to master\n\nmaster\n|\n|------ A\n|\n|\n|\n|\n\n5) Rebase A to master\n\nmaster\n|\n|\n|\n|\n|\n|----- A\n\nI found that, checking out A, my files in the now renamed directories\nare as the were in B, i.e. not including the changes made in A,\nbecause I have rebased A to master and git didn't realize that the\nfiles in old_directory_name are the same as in new_directory_name so\nthey should have been merged.\n\nEither this is a git bug or not, can anyone suggest a way to fix this?\nAll I've thought so far is to git-format-patch the patches that I had\nin A, use sed to replace the old_directory_name with the new one,\ncreate a new branch called A2 at master's head, apply the patches\nthere and git-branch -D A.\n\nThanks!\n\nPS: please CC me as I'm not on the list.\n\n-- \nSalvatore Iovene\nhttp://www.iovene.com/\nhttp://www.geekherocomic.com/\n"},{"id":"106424","messageId":"m3hc2gup2n.fsf@localhost.localdomain","threadId":"18043","inReplyTo":"c64207c00902270055q57442e2dmd81c197419dda71a@mail.gmail.com","subject":"Re: Problems rebasing branch after renaming files","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2009-02-27T10:55:31Z","receivedAt":"2009-02-27T10:55:31Z","isPatch":false,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"Salvatore Iovene <salvatore.iovene@googlemail.com> writes:\n\n> Hi list,\n> I ran into a problem, and I'm unsure it's a git bug or a misuse of mine.\n\n[...]\n> 3) Create branch B and work on it. In this branch, rename a directory\n> containing source files with git-mv\n> 4) Merge B to master\n> 5) Rebase A to master\n\n[...]\n> I found that, checking out A, my files in the now renamed directories\n> are as the were in B, i.e. not including the changes made in A,\n> because I have rebased A to master and git didn't realize that the\n> files in old_directory_name are the same as in new_directory_name so\n> they should have been merged.\n> \n> Either this is a git bug or not, can anyone suggest a way to fix this?\n> All I've thought so far is to git-format-patch the patches that I had\n> in A, use sed to replace the old_directory_name with the new one,\n> create a new branch called A2 at master's head, apply the patches\n> there and git-branch -D A.\n\nIn short: you have rename in mainline, and want to rebase branch from\nbefore rename.\n\nThis problem is not bug in git, it is rather limitation of default\npatch based rebase. The git-format-patch | git-am pipeline is fast,\nbut it cannot deal with renames in mainline. You have to use\nmerge-based rebase, i.e. use\n\n  $ git rebase --merge <upstream>\n\n>From git-rebase(1):\n\n  -m, --merge\n    Use merging strategies to rebase. When the recursive (default) merge\n    strategy is used, this allows rebase to be aware of renames  on  the\n    upstream side.\n\n  -s <strategy>, --strategy=<strategy>\n    Use  the  given  merge  strategy;  can be supplied more than once to\n    specify them in the order they should be tried. If there  is  no  -s\n    option, a built-in list of strategies is used instead\n    (git-merge-recursive when merging a single head, git-merge-octopus\n    otherwise). This implies --merge.\n\nOr use \"git rebase --interactive\".\n\n-- \nJakub Narebski\nPoland\nShadeHawk on #git\n"}]}