{"thread":{"id":"46627","subject":"git-svn: Handling of branches created from subfolders","startedAt":"2017-08-19T12:45:52Z","lastAt":"2017-08-20T17:42:20Z","messageCount":3,"participants":["Jan Teske","Andreas Heiduk"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"326769","messageId":"1ED00C5D-177C-4F95-8261-BFB7345B7C08@gmail.com","threadId":"46627","inReplyTo":null,"subject":"git-svn: Handling of branches created from subfolders","fromName":"Jan Teske","fromEmail":"jan.teske@gmail.com","sentAt":"2017-08-19T12:45:58Z","receivedAt":"2017-08-19T12:45:52Z","isPatch":false,"sender":{"key":"jan.teske@gmail.com","avatar":null},"body":"Hello,\n\nI’m trying to do a one-time conversion of a large SVN repository to git using git-svn. Unfortunately, this SVN repo contains a substantial amount of non-standard branches created from a subfolder of trunk/. Users that only need to work on part of the code inside the repo usually create such branches to avoid having to download unneeded files.\n\nA toy example showing what I’m talking about:\n\ntrunk/\n    - subfolder1/\n        - …\n    - subfolder2/\n        - …\nbranches/\n    - branch1/ (initially cp’ed from trunk/subfolder1)\n        - …\n    - branch2/ (initially cp’ed from trunk/subfolder2)\n        - …\n    - branch3/ (initially cp’ed from trunk)\n        - …\n\nWhile in my experience, git-svn is able to correctly handle branches/branch3, it fails on branch1 and branch2. By \"fails\" I mean that it still performs the conversion, but any relationship to the trunk is completely missing. Instead, in the resulting git repository it looks like those branches have a completely separate history, starting from nothing.\n\nIs there any way to fix such branches from subfolders in a way that they integrate correctly with the converted git repository, without losing any (or at least too much) history? If this is not possible with git-svn directly, maybe I could prepare the SVN repo or post-process the converted git repository somehow?\n\nThanks!\n    "},{"id":"326814","messageId":"8c910a5b-ed96-41d4-d157-f138af51011f@gmail.com","threadId":"46627","inReplyTo":"1ED00C5D-177C-4F95-8261-BFB7345B7C08@gmail.com","subject":"Re: git-svn: Handling of branches created from subfolders","fromName":"Andreas Heiduk","fromEmail":"asheiduk@gmail.com","sentAt":"2017-08-20T10:27:59Z","receivedAt":"2017-08-20T10:28:07Z","isPatch":false,"sender":{"key":"asheiduk@gmail.com","avatar":"https://avatars.githubusercontent.com/u/9371344?v=4"},"body":"Am 19.08.2017 um 14:45 schrieb Jan Teske:\n> Is there any way to fix such branches from subfolders in a way that they integrate correctly with the converted git repository, without losing any (or at least too much) history? If this is not possible with git-svn directly, maybe I could prepare the SVN repo or post-process the converted git repository somehow?\n\nYou can use `git replace --graft` to connect the first commit of the\nloose branches with their source. After all connections are in place you\ncan use `git filter-branch` to make the replacements permanent.\n\nThis will not change the content or directory structure of branch1 or\nbranch2 but the diff with their parent commits will show up as a huge\ndelete/rename operation. So merging/Cherry-picking between trunk and\nbranch1/branch2 will be ... challenging.\n"},{"id":"326824","messageId":"74EA70E5-0B8A-4D34-B5EA-8C97A10F3D0F@gmail.com","threadId":"46627","inReplyTo":"8c910a5b-ed96-41d4-d157-f138af51011f@gmail.com","subject":"Re: git-svn: Handling of branches created from subfolders","fromName":"Jan Teske","fromEmail":"jan.teske@gmail.com","sentAt":"2017-08-20T17:42:11Z","receivedAt":"2017-08-20T17:42:20Z","isPatch":false,"sender":{"key":"jan.teske@gmail.com","avatar":null},"body":"\n> On 20. Aug 2017, at 12:27 , Andreas Heiduk <asheiduk@gmail.com> wrote:\n> \n> Am 19.08.2017 um 14:45 schrieb Jan Teske:\n>> Is there any way to fix such branches from subfolders in a way that they integrate correctly with the converted git repository, without losing any (or at least too much) history? If this is not possible with git-svn directly, maybe I could prepare the SVN repo or post-process the converted git repository somehow?\n> \n> You can use `git replace --graft` to connect the first commit of the\n> loose branches with their source. After all connections are in place you\n> can use `git filter-branch` to make the replacements permanent.\n> \n> This will not change the content or directory structure of branch1 or\n> branch2 but the diff with their parent commits will show up as a huge\n> delete/rename operation. So merging/Cherry-picking between trunk and\n> branch1/branch2 will be ... challenging.\n\nThat’s really helpful, thanks!\n\nI even solved the problem of the challenging merging between the converted branches and trunk by using another filter-branch to rewrite all the commits in branch1/branch2 to make all their modifications in the respective subfolders (effectively fixing the directory structure to fit trunk). This answer was helpful for how to do this: https://unix.stackexchange.com/a/280229\n\nSo, for future reference, the following post-processing seems to work:\n\n1. Use filter-branch to move all the commits the the correct subfolder.\n2. Use `git replace --graft` to connect the first commit of the branch to its correct parent commit.\n3. Use `git replace --graft` to add the missing parents of any merge commits the branch was part of.\n4. Use filter-branch again to make the replacements permanent.\n\n\n"}]}