Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
681 views
in Technique[技术] by (71.8m points)

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...