Search code examples
gitgit-workflow

How to transfer multiply commits from one branch to another using git?


There are two branches:
- production branch which contains product accepted by customer
- develop branch where developers perform their creepy experiments
Once upon a time young developer decided to branch his super feature from productive branch.
So the qustions:
1). How can I transfer production branch to develop without merging all acenstors of feature from prod branch. The picture explains better:

enter image description here

The first question is for practice, another questions for curiosity:
2). Same as 1) + I need to keep feature branch from production also
3). Like 1), but I want transfer consistent set of commits "F" and don't want transfer "E" commits
4). I want transfer E and F excluding 2 commits, 1 commit from set "E" and 1 commit from set "F".
5). Can I automatically resolve conflicts in favor of one of branches?

I found git cherry-pick command, but seems it is not the best way for whole branch. Should i study git rebase or something else? Which way is the best for my problem?

Thanks and sorry for my poor English.


Solution

  • git checkout develop
    git cherry-pick production..feature
    

    does exactly what you want for your first question, it cherry-picks every commit in feature that isn't also in production's history. For the rest of your questions, various other ways of specifying commit ranges as found in the gitrevisions manpage will work, and after you're familiar with those, and it starts to seem a bit tedious working out how to specify a list or you start wanting to make amendments as you go, you'll be ready to appreciate rebase -i.

    One small detail: cherry-pick and rebase make new commits.