Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git. Merging changes from one file to another files WITHIN the same branch

Tags:

git

merge

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 :/

like image 279
Nadine Avatar asked Mar 25 '12 17:03

Nadine


1 Answers

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
like image 195
VonC Avatar answered Oct 27 '22 20:10

VonC