0

I have next repository state:

enter image description here

I have started working on feature 1 (feature branch), next I have switched to another_feature, addition and addition2 which were merged to master.

Now I returned to feature and I understand that my feature can not work without addition. What do I need to do in this case?

I cannot use merge because in this case I will have another_feature in the feature:

git checkout feature
git merge addition

I can use and it work fine:

git checkout feature
git cherry-pick 9040

But it is very inconvenient if I have too many commits in addition branch. How can I cherry-pick all commits from one branch and only from this branch?

And in this case I will have 9040-commit two times in my master after merge feature. May be there is a better way to have changes from addition branch in the feature branch?

Addition: after commit feature 1 I have created Pull Request and we start to discuss it. It is very undesirable to close that PR and open the new one.

ceth
  • 44,198
  • 62
  • 180
  • 289
  • Why don't you want `another_feature` changes in `feature`? – mnestorov Jan 26 '20 at 09:49
  • Does this answer your question? [How to cherry pick a range of commits and merge into another branch?](https://stackoverflow.com/questions/1994463/how-to-cherry-pick-a-range-of-commits-and-merge-into-another-branch) – caramba Jan 26 '20 at 09:51
  • @mnestorov, because I have Pull Request and I don't have to see `another_feature` and many other commits to see in my Pull Request. – ceth Jan 26 '20 at 09:59

1 Answers1

0

What you are looking for is a rebase. Rebasing moves the current branch from the current base commit to a new base commit to make sure that all work done up to now will be added to the history but starting from a different point in time.

Suppose this is your history

a -> b -> c : master
  \>d : feature

Then a rebase of feature on master will look like this

a -> b -> c : master
           \>d : feature

an in your rebased feature branche you will have commit b and c before the commit d

Mind that this is not easy if the master branch has progressed long and you may have to fix merge conflicts!

edoput
  • 1,212
  • 9
  • 17
  • I have already opened Pull Request and `rebase` will broke my Pull Request because reviewers will see all the changes from all commits. – ceth Jan 26 '20 at 10:02
  • the reviewers will see the commits that are not in the target branch. Again suppose that commit d requires a feature in commit c then rebasing your work on c will make the code work and the difference between the master branch and the feature branch is going to be only the commit d. You may have to rewrite history also on the remote feature branch by using the `git push --force-with-lease` command or `git push --force` to make sure you can see changes on the web ui – edoput Jan 26 '20 at 10:08