简体   繁体   中英

Git merge feature on develop branch to another already existing develop branch

I have a git repo (inherited) and branch lets call "develop" (well A for the rest of the question). That branch has 2 more branches where it is the parent called "B" and "C" where customer specific changes happen. However that branch (A labeled below) is roughly 1 year old so B and C have diverged. I'm working on breaking out the customer specific features and rejoining the changes back into A so we have a common ancestor but not there yet. We do feature branches workflow so I created a new branch off "B" (which is customer1 in this case) called D.

A -> B
    -> D
  -> C

I did 100's of commits working on the new feature and did a 'git co B && git merge D' which in this case happen to be 100% new files (well except for the.gitignore) for branch B. I did not squash and my git log now looks like

*   250f8fd4 - (origin/B, origin/HEAD, B) Add new files for project X (3 days ago) <me>
|\
| * f8a1a83e - (origin/D, D) cleaning up before merge (3 days ago) <me>
* | 84bc9cb5 - cleaning up before merge (3 days ago) <me>
|/
* 08510627 - variablize and not hardcode value (3 days ago) <me>

Then I git pushed, and verified everything worked. I now want those same files to be in branch C. Since these are 100% new files and I can just copy them from B to C but I don't want to have merge conflicts in the future when I do collapse all the branches back into A.

Running 'git merge 250f8fd4' results in ALL changes since B diverged from A being applied to C (including overwriting customer specific files and changes) and generates thousands of merge conflicts. I use git merge --abort to undo it.

$ git cherry-pick 250f8fd4
error: commit 250f8fd4e41c069eb1a2861855a4db30a1fba658 is a merge but no -m option was given.
fatal: cherry-pick failed

fails, so lets try telling it which side

$ git cherry-pick -m 1 250f8fd4
On branch C
Your branch is up to date with 'origin/C'.

You are currently cherry-picking commit 250f8fd4.

nothing to commit, working tree clean
The previous cherry-pick is now empty, possibly due to conflict resolution.
If you wish to commit it anyway, use:

    git commit --allow-empty

Otherwise, please use 'git reset'

Regardless if i use -m 1 or -m 2 it always results in empty commit.

How do i do this the "git" way and get my feature changes into multiple NON master/develop branches? I guess I also haven't tried merging from D into C but I don't think that would work either.

git hinted it in the cherry-pick error message: commit 250f8fd4 is just the merge commit; the actual changes are contained in 84bc9cb5 and f8a1a83e .

There are only two commits, you can cherry-pick them easily:

git cherry-pick 84bc9cb5 f8a1a83e

If there were more commits, or if you wanted a more systematic way to select a bunch of commits and replay them on top of C , you can use the --onto option of git rebase :

# this will rebase :
#  - on top of commit C (--onto C)
#  - commits starting from 08510627 (this commit will *not* be included)
#  - up to 250f8fd4 (included)
git rebase --onto C 08510627 250f8fd4

# once the rebase is completed, you can update branch C to this new commit :
git branch -f C
git checkout C

# or :
git checkout C
git merge --ff-only <rebased-commit>

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