How to merge only some files?

I am trying to merge the commit part from the default branch (not all files and parts of other files) into a named branch. I tried graft , but it just takes all the commit, giving me the opportunity to choose. How to do it?

Example:

 A---B---C---D \ -E---(G) 

G does not exist yet. Let's say that C and D added 5 files and 5 files. I want G have 2 out of 5 files added to C , all changes to one of the files and one modification to another file. I would ideally want him to have something similar from D too.

When I selected graft to local... all I got is a set of C changes. The same goes for merge with local...

+4
source share
1 answer

A merge unit is a whole set of changes, so C and D had to be done in smaller parts. Now you can merge all this and return some files, but this will lead to the fact that you will not be able to merge the rest later - they are already considered merged.

What I would do is make a branch parallel to the CD embedded in B in your example, which contains copies of the changes in C and D, but splits them into consecutive parts. You can then merge the whole changes with it and close (or perhaps even delete) the original CD branch.

  C---D / A---B--C1--D1--C2--D2 (equivalent to C--D) \ E---(G?) 

In the above example, C1 and C2 together are equivalent to C. While I was on it, I went ahead and reordered four new change sets (use a rewrite history tool such as rebase ) so that you can then simply merge D1 with E:

  C---D / A---B--C1--D1--C2--D2 \ \ E------G 

If reordering new changesets is not an option, you will need to do some fancy branches to do partial revisions in the order of C1, D1, C2, D2; there are probably far fewer problems using graft (or transplant ) to copy changes that you are not allowed to merge separately. For example, in the future you can still combine C1, but then you need a copy of D1 (denoted by D1 '), since there is no way to combine it without pulling C2 along with it.

  C---D / A---B--C1--C2--D1--D2 \ \ E--G1--D1' 
+4
source

Source: https://habr.com/ru/post/1485698/


All Articles