{"thread":{"id":"25234","subject":"merge removed content back into current content","startedAt":"2010-09-25T03:06:10Z","lastAt":"2010-09-28T16:49:10Z","messageCount":5,"participants":["Neal Kreitzinger","Elijah Newren","Eric Raible"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"151599","messageId":"i7jp1a$kc0$1@dough.gmane.org","threadId":"25234","inReplyTo":null,"subject":"merge removed content back into current content","fromName":"Neal Kreitzinger","fromEmail":"neal@rsss.com","sentAt":"2010-09-25T03:06:10Z","receivedAt":"2010-09-25T03:06:10Z","isPatch":false,"sender":{"key":"neal@rsss.com","avatar":null},"body":"How do I tell git to merge a single program from an old commit into the \ncurrent version of that program in the HEAD commit?  In this scenario, I \nwant to get back some removed code but still keep the new code.\n\ne.g.\n\nCommit-1 = initial commit containing Program-A, and other programs\n\nCommit-2 = add Changeset-1 to Program-A , and make changes to other programs\n\nCommit-3 = remove Changeset-1 from Program-A, then add Changeset-2 to \nProgram-A, and make changes to other programs\n\n*desired* Commit-4 = only merge Program-A from Commit-2 into Program-A of \nCommit-3, and don't change any other programs\n(in other words, get my old changes from Commit-2 back, but don't loose the \nnew changes from Commit-3)\n\nv/r,\nNeal \n"},{"id":"151696","messageId":"AANLkTimxHbCktv=kaq0UfV+u1kH1Pb2LYA2Xi=qkgduW@mail.gmail.com","threadId":"25234","inReplyTo":"i7jp1a$kc0$1@dough.gmane.org","subject":"Re: merge removed content back into current content","fromName":"Elijah Newren","fromEmail":"newren@gmail.com","sentAt":"2010-09-25T23:43:03Z","receivedAt":"2010-09-25T23:43:03Z","isPatch":false,"sender":{"key":"newren@gmail.com","avatar":"https://avatars.githubusercontent.com/u/5455730?v=4"},"body":"On Fri, Sep 24, 2010 at 9:06 PM, Neal Kreitzinger <neal@rsss.com> wrote:\n> How do I tell git to merge a single program from an old commit into the\n> current version of that program in the HEAD commit?  In this scenario, I\n> want to get back some removed code but still keep the new code.\n>\n> e.g.\n>\n> Commit-1 = initial commit containing Program-A, and other programs\n>\n> Commit-2 = add Changeset-1 to Program-A , and make changes to other programs\n>\n> Commit-3 = remove Changeset-1 from Program-A, then add Changeset-2 to\n> Program-A, and make changes to other programs\n>\n> *desired* Commit-4 = only merge Program-A from Commit-2 into Program-A of\n> Commit-3, and don't change any other programs\n> (in other words, get my old changes from Commit-2 back, but don't loose the\n> new changes from Commit-3)\n\nDoes something like:\n  git diff commit1 commit2 -- ProgramA | git apply\ndo what you need?\n\nIf diff+apply doesn't work[1], you can try\n  git cat-file -p commit1:ProgramA > base\n  git cat-file -p commit2:ProgramA > other\n  git cat-file -p commit3:ProgramA > current\n  git merge-file current base other\n\n[1] e.g. would cause conflicts -- btw, does anyone know how to force\ngit apply to proceed and add conflict markers if necessary rather than\njust bailing out?\n"},{"id":"151852","messageId":"4CA0E313.4090501@nextest.com","threadId":"25234","inReplyTo":"AANLkTimxHbCktv=kaq0UfV+u1kH1Pb2LYA2Xi=qkgduW@mail.gmail.com","subject":"Re: Re: merge removed content back into current content","fromName":"Eric Raible","fromEmail":"raible@nextest.com","sentAt":"2010-09-27T18:31:47Z","receivedAt":"2010-09-27T18:31:47Z","isPatch":false,"sender":{"key":"raible@nextest.com","avatar":null},"body":"On 11:59 AM, Elijah Newren wrote:\n\n> btw, does anyone know how to force\n> git apply to proceed and add conflict markers if necessary rather than\n> just bailing out?\n\nIt's not quite the same, and you probably already know about it,\nbut there's always: git apply --reject\n"},{"id":"151931","messageId":"i7t52j$hl3$1@dough.gmane.org","threadId":"25234","inReplyTo":"AANLkTimxHbCktv=kaq0UfV+u1kH1Pb2LYA2Xi=qkgduW@mail.gmail.com","subject":"Re: merge removed content back into current content","fromName":"Neal Kreitzinger","fromEmail":"neal@rsss.com","sentAt":"2010-09-28T16:26:21Z","receivedAt":"2010-09-28T16:26:21Z","isPatch":false,"sender":{"key":"neal@rsss.com","avatar":null},"body":"\n>\"Elijah Newren\" <newren@gmail.com> wrote in message \n> >news:AANLkTimxHbCktv=kaq0UfV+u1kH1Pb2LYA2Xi=qkgduW@mail.gmail.com...\n>On Fri, Sep 24, 2010 at 9:06 PM, Neal Kreitzinger <neal@rsss.com> wrote:\n>> How do I tell git to merge a single program from an old commit into the\n>> current version of that program in the HEAD commit? In this scenario, I\n>> want to get back some removed code but still keep the new code.\n>>\n>> e.g.\n>>\n>> Commit-1 = initial commit containing Program-A, and other programs\n>>\n>> Commit-2 = add Changeset-1 to Program-A , and make changes to other \n>> programs\n>>\n>> Commit-3 = remove Changeset-1 from Program-A, then add Changeset-2 to\n>> Program-A, and make changes to other programs\n>>\n>> *desired* Commit-4 = only merge Program-A from Commit-2 into Program-A of\n>> Commit-3, and don't change any other programs\n>> (in other words, get my old changes from Commit-2 back, but don't loose \n>> the\n>> new changes from Commit-3)\n>\n>Does something like:\n>  git diff commit1 commit2 -- ProgramA | git apply\n>do what you need?\n>\nAll of our source conflicts because we add a user/datestamp to the first \nline.  We do this to insure the programmer reviews the merge.\nHowever, I never used git apply before so that was interesting to learn.\n\n>If diff+apply doesn't work[1], you can try\n>  git cat-file -p commit1:ProgramA > base\n>  git cat-file -p commit2:ProgramA > other\n>  git cat-file -p commit3:ProgramA > current\n>  git merge-file current base other\n>\nThis method is also something new to me, but it seems too manual.  It also \ndoes not do the normal git merge where the results are in the index.  An \neasier method is to do this:\ngit difftool commit1 commit2 -- ProgramA\nand then use kdiff3's merge option.  this does not include the common \nancestor as a reference like a normal git merge conflict followed by git \nmergetool (kdiff3), but is user friendly.  However, I'm not crazy about it \nbecause I'd rather have the merge results in the index and use git mergetool \nlike I do for commit merges.\n\n>[1] e.g. would cause conflicts -- btw, does anyone know how to force\n>git apply to proceed and add conflict markers if necessary rather than\n>just bailing out? \n"},{"id":"151932","messageId":"i7t6ct$o94$1@dough.gmane.org","threadId":"25234","inReplyTo":"i7jp1a$kc0$1@dough.gmane.org","subject":"Re: merge removed content back into current content","fromName":"Neal Kreitzinger","fromEmail":"neal@rsss.com","sentAt":"2010-09-28T16:49:10Z","receivedAt":"2010-09-28T16:49:10Z","isPatch":false,"sender":{"key":"neal@rsss.com","avatar":null},"body":"\n\"Neal Kreitzinger\" <neal@rsss.com> wrote in message \nnews:i7jp1a$kc0$1@dough.gmane.org...\n> How do I tell git to merge a single program from an old commit into the \n> current version of that program in the HEAD commit?  In this scenario, I \n> want to get back some removed code but still keep the new code.\n>\n> e.g.\n>\n> Commit-1 = initial commit containing Program-A, and other programs\n>\n> Commit-2 = add Changeset-1 to Program-A , and make changes to other \n> programs\n>\n> Commit-3 = remove Changeset-1 from Program-A, then add Changeset-2 to \n> Program-A, and make changes to other programs\n>\n> *desired* Commit-4 = only merge Program-A from Commit-2 into Program-A of \n> Commit-3, and don't change any other programs\n> (in other words, get my old changes from Commit-2 back, but don't loose \n> the new changes from Commit-3)\n>\nHere is a method for invoking git merge and git mergetool, but its very \nonerous and I'm hoping there's a more straightforward method to merge using \nthe index so let me know if you have something better.  I've published these \nsteps to my coworkers to answer their request for merging just two programs \n(as opposed to 2 commits), but it seems pretty ridiculous to have to go thru \nall of this just to merge one version of a program into another.\n\nUsing git diff commit-2 commit-3 -- Program-A and then using kdiff3's merge \noption is pretty easy, but is not using the index, conflicts, or \ngit-mergetool (common ancestor 3-way merge) so I'm not crazy about it, but I \nhave to recommend it over the cherry-pick because its so straightforward and \nthe cherry-pick is so convoluted.  I feel like I'm going around git when I \nuse git difftool (kdiff3 merge) to do this and that I'm going thru git when \nI use the cherry-pick methods below, but they are way more work!\n\nCherry-pick methods:\n\nPossibly a more correct way to perform the merge is to let git run the merge \nand generate conflicts for you to resolve like any other git merge with git \nmergetool utilizing the common ancestor history.\n\n\n\nScenario:  use git to merge an old program version into the current program \nversion and git-mergetool to resolve conflicts.  The old version does not \nreside in a commit by itself so therefore that commit cannot be cherry \npicked.\n\n\n\nAssuming you are on already on a branch that contains the old version and \nnew version of program in its history.\n\n(1)  In gitk view the changes made to the program in question\n\n$ gitk 12.5/Generic/Base -- SRC/SALES/SALEOUT\n\n(2)  Right click on the commit containing the old version of the program and \ntag it, e.g. WKTG/MRG/Theirs/SALEOUT\n\n(in a merge, \"ours\" = version in current branch HEAD, \"theirs\" = version \nfrom other branch being merged into current branch)\n\n\n\nDecision:\n\nIf commit containing old version contains a few other objects with changes:\n\n(3) Cherry-pick the commit onto your branch.\n\n$ git cherry-pick WKTG/MRG/Theirs/SALEOUT (Cherry pick will inform you of \nconflicts)\n\n(4) Discard the cherry-picked objects you don't want.\n\n$ git checkout --ours otherobject1 otherobject2 otherobject3 etc.\n\n(5) Merge your program with git-mergetool.\n\n$ git mergetool (Merge the stuff using kdiff3)\n\n$ git add SRC/SALES/SALEOUT\n\n$ git commit -c WKTG/MRG/Theirs/SALEOUT (Cherry pick will tell you exactly \nhow to do the git commit -c)\n\nYou're Done.\n\n\n\nIf commit containing old version contains \"too many\" other objects with \nchanges, it may be faster to do this:\n\n(3) Create a branch that points to MARK/MRG/Theirs/SALEOUT\n\n$ git checkout -b WKBR/MRG/Theirs/SALEOUT WKTG/MRG/Theirs/SALEOUT\n\n(4) Split the commit to isolate the \"cherry\" (the old version of the \nprogram) that you want to pick.\n\n$ git rebase -i --onto WKBR/MRG/Theirs/SALEOUT~1 WKBR/MRG/Theirs/SALEOUT~1 \nWKBR/MRG/Theirs/SALEOUT\n\n(a) Change \"pick\" to \"edit\" for the commit in the rebase editor and save it. \nRebase will inform you that it stopped after that commit.\n\n(b) \"Undo\" the commit:\n\n$ git reset HEAD^ (this will rollback the HEAD and index to the prior \ncommit, but leave the commit changes in your working tree)\n\n(c) Stage the old version of the program and commit it.\n\n$ git add SRC/SALES/SALEOUT\n\n$ git commit\n\n(d) Commit the rest of the stuff.\n\n$ git add .\n\n$ git commit\n\n(5) Tag the commit containing the old version of the program.\n\n$ git logr (copy the sha1 of the second to last commit)\n\n$ git tag <sha1-of-2nd-to-last-commit> WKTG/MRG/Cherry/SALEOUT\n\n(6) Cherry pick that cherry commit onto your branch.  Cherry-pick will \ninform you of the conflict (user/datestamp will at least conflict).\n\n$ git checkout <project-branch>\n\n$ git cherry-pick --no-commit WKTG/MRG/Cherry/SALEOUT\n\n(7) Merge using git mergtool.\n\n$ git mergetool (Merge the stuff using kdiff3)\n\n$ git add SRC/SALES/SALEOUT\n\n$ git commit -c WKTG/MRG/Theirs/SALEOUT (Cherry pick will tell you exactly \nhow to do the git commit -c)\n\nYou're Done.\n\n\n\nv/r,\n\nNeal\n"}]}