How to move a commit from one branch to another

I have two functions I'm working on

General - Entries - A - B - C Feat1

General - Records - D - E - F Feat2

The problem is that for testing Feat2, I really need Feat1, but I still want them to be separate branches, because they are different. What is a good way to make changes to Feat2, and then quickly create a third branch that is taken together, and this does not require me to destroy it every time.

General - Commits - Feat1 - Feat2

What i did is

git checkout feat2 git branch -b combo git rebase -i feat1

But when I do updates for feat2, I don’t know how to merge these new changes.

+5
source share
2 answers

Merger

You can join instead of rebase. Since your combined affiliate is for testing purposes only, you don’t have to worry about the story being a bit messy.

I.e:

 git checkout feat2 git branch -b combo git merge feat1 

Later, when you update feat2:

 git checkout combo git merge feat2 

Whenever you do an update for feat1 or feat2, combine this into a combo.

The disadvantage is that you have to merge all the commits in both branches. If you do not need changes, you will have to make a separate commit that removes these changes in the combined branch.

relocation

You can reinstall additional commits from feat2 to combos.

Suppose you add some commits to feat2, then move these commits to combos:

 git rebase --onto combo lastcommittoexcludeonfeat2 feat2 

Also, before making changes to feat2, add a branch or tag, for example:

 git checkout -b lastfeat2rebase git checkout feat2 git commit ... # more commits here to feat2 git rebase --onto combo lastfeat2rebase feat2 

Please note that once you go with the rebase option, you can no longer use the merge option. If you use the merge option, you can go to the reinstall option later.

+4
source

There are basically two options here.

  • You can use cherry-pick to copy new feat2 commits to combo .
  • Instead of rebooting you can merge

Cherry pick

To blacken select new commits on feat2 to combo , follow these steps:

 git checkout combo git cherry-pick <new commit> <new commit> <new commit> 

Merger

Or, alternately, you can team up, not reinstall. For instance. To create combos:

 git checkout -b combo feat1 git merge feat2 

Then, to "merge new changes" with feat2 , just ...

 git merge feat2 

Similarly, to merge new commits on feat1 :

 git merge feat1 
+6
source

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


All Articles