Merge some files now and a little later

I am in branch B. After a bunch of commits, several files are ready / needed by branch A, but many of them are not ready / needed. I want to merge only those files, keeping a proper git history. Later, when I really merge, I don’t want to mislead the trace of the origin of these changes - they should correctly refer to the commits from which they came, although the changes in other files that were part of these commits were not merged (yet). I assume that this means that dividing commits into pieces that do against does not apply to these files.

All proposed solutions for this wind lose the history of these changes and cause a big problem when I later want to combine B into A, but some of the B-changes already exist. I want a solution that avoids this.

In the turtle, I can look at the log for one file and select the previous version to return. So basically, I could create a new C branch from B and return all the files that I don't want to merge with to the point where B is forked with A. Then I could merge C into A. It seems to be correct to track the git history and allows me to combine B into A, not surprising that some changes to B already exist.

But it hurts to manually identify and return 20 files when I just want to merge 2. Why is this not an ordinary one-step operation? How the turtle will return work - since it can work with one file, it should be a sub-commit, which is the important function I'm looking for. Does this discard the fact that I am moving from a newer version to an older one, and make it look like I just made some manual changes that would then conflict with the possible merging of B back to A?

+2
source share
2 answers

You are looking for cherry pick , a method for selecting only specific commits from a branch to be merged.

To combine only certain files (when you do not want to combine the whole commit), you have several solutions, really, I like to use one that is well expressed in this article , it’s a pain in the ass, one way or another, bit it, the easier I found for that kind of thing.

You can also split some commits and merge only those that contain the necessary files, and you can do, for example, that another article says

+1
source

This is not a normal one-step operation, because Git is a content tracker, not a file tracker .

You can easily apply changes to specific files from branch B to branch A, like Tortoise:

 # raw file, no history git checkout A git checkout B myfile 

or

 # copy a set of history from someplace else git checkout A git cherry-pick commit-hash-1..commit-hash-2 

but none of them will save the story as a merge with branch B. If this is what you are trying to do, depending on how the commits in branch B are organized, this might be better for you: Git: piecewise merge method for major changes version?

0
source

All Articles