git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: merge removed content back into current content

From
NKNeal Kreitzinger <neal@rsss.com>
Date
Sep 28, 2010, 16:26 UTC
Message-ID
<i7t52j$hl3$1@dough.gmane.org>
In-Reply-To
<AANLkTimxHbCktv=kaq0UfV+u1kH1Pb2LYA2Xi=qkgduW@mail.gmail.com>
Show 27 quoted lines
>"Elijah Newren" <newren@gmail.com> wrote in message 
> >news:AANLkTimxHbCktv=kaq0UfV+u1kH1Pb2LYA2Xi=qkgduW@mail.gmail.com...
>On Fri, Sep 24, 2010 at 9:06 PM, Neal Kreitzinger <neal@rsss.com> wrote:
>> How do I tell git to merge a single program from an old commit into the
>> current version of that program in the HEAD commit? In this scenario, I
>> want to get back some removed code but still keep the new code.
>>
>> e.g.
>>
>> Commit-1 = initial commit containing Program-A, and other programs
>>
>> Commit-2 = add Changeset-1 to Program-A , and make changes to other 
>> programs
>>
>> Commit-3 = remove Changeset-1 from Program-A, then add Changeset-2 to
>> Program-A, and make changes to other programs
>>
>> *desired* Commit-4 = only merge Program-A from Commit-2 into Program-A of
>> Commit-3, and don't change any other programs
>> (in other words, get my old changes from Commit-2 back, but don't loose 
>> the
>> new changes from Commit-3)
>
>Does something like:
>  git diff commit1 commit2 -- ProgramA | git apply
>do what you need?
>

All of our source conflicts because we add a user/datestamp to the first line. We do this to insure the programmer reviews the merge. However, I never used git apply before so that was interesting to learn.

Show 6 quoted lines
>If diff+apply doesn't work[1], you can try
>  git cat-file -p commit1:ProgramA > base
>  git cat-file -p commit2:ProgramA > other
>  git cat-file -p commit3:ProgramA > current
>  git merge-file current base other
>

This method is also something new to me, but it seems too manual. It also does not do the normal git merge where the results are in the index. An easier method is to do this: git difftool commit1 commit2 -- ProgramA and then use kdiff3's merge option. this does not include the common ancestor as a reference like a normal git merge conflict followed by git mergetool (kdiff3), but is user friendly. However, I'm not crazy about it because I'd rather have the merge results in the index and use git mergetool like I do for commit merges.

>[1] e.g. would cause conflicts -- btw, does anyone know how to force
>git apply to proceed and add conflict markers if necessary rather than
>just bailing out? 
Previous: Eric RaibleNext: Neal Kreitzinger
Message 4 of 5 in “merge removed content back into current content”
  1. Neal KreitzingerSep 25, 2010
  2. Elijah NewrenSep 25, 2010
  3. Eric RaibleSep 27, 2010
  4. Neal KreitzingerSep 28, 2010
  5. Neal KreitzingerSep 28, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.