简体   繁体   中英

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM