10

I have two files:

    master/newsletter1/file.html 
    master/newsletter2/file.html

newsletter1/file.html has a lot of new changes that I want to merge into newsletter2/file.html. How can I achieve this? Everything I have read seems to resolve around merging between branches, but these are in the same branch :/

Nadine
  • 777
  • 1
  • 11
  • 24

1 Answers1

11

I would recommend using a third-party diff tool of your choice, in order to do a manual merge between the two files.
This is not about source-control (ie managing the history of versions for one file).
This is about reporting changes from one files to another (the source-control tool will then pick up the new version for the second file).


As Jefromi mentions in the comments, and as he explains in "run git merge algorithm on two individual files", git merge-file can actually merge two different files, provided a common ancestor is provided.

git merge-file <current-version> <common-ancestor> <other-version>

In your case, you could try with the common ancestor being identical to the current file.

git merge-file master/newsletter2/file.html master/newsletter1/file.html master/newsletter2/file.html
Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • You're absolutely right. I have used netbeans for this instead. – Nadine Mar 25 '12 at 17:22
  • 2
    If you have something reasonable to use for a common ancestor, you could use `git merge-file`. – Cascabel Mar 25 '12 at 17:28
  • @Jefromi interesting. What if the common ancestor is the same than "current file" (ie the destination)? That could work for detecting changes introduces by the first file (the source) – VonC Mar 25 '12 at 17:45
  • 3
    This got me on the right track, but running the command does nothing in my repository. I guess that's because `` and `` are the same. I don't have a third ancestor to point to, unless it's possible to point to a specific commit ID, but I don't know the syntax to express that and the documentation doesn't mention it. – Asbjørn Ulsberg Feb 03 '15 at 10:25