T
T
tamtakoe2014-01-18 21:21:21
git
tamtakoe, 2014-01-18 21:21:21

How to merge a branch derived from another branch into master in Git?

There is:
master -> m10 (points to the m10 commit)
A branch was formed from m10 (to which a number of commits were made)
server -> s15
From s15 a branch was formed
experiment -> e1
Next, a new commit was added to the server. Became
server -> s16
Then server was merged with master. It turned out
master -> m11
----
It is necessary to make the experiment -> e1 branch inherited from master -> m11. How to do it? As I understand it, if you do a rebase, then it will become a new commit of the master, but you need it to remain a separate branch.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
A
Artyom Zubkov, 2014-01-18
@artzub

Rebase will just make it so that the head of the experiment branch will be the last m11 commit in master.

$ git init
$ echo 111 > 1.txt
$ git add .
$ git commit -m "m10"
$ git checkout -b server
$ echo ser >> 1.txt
$ git commit -am "s11"
$ echo ser1 >> 1.txt
$ git commit -am "s12"
$ echo ser2 >> 1.txt
$ git commit -am "s13"
$ echo ser3 >> 1.txt
$ git commit -am "s14"
$ echo ser4 >> 1.txt
$ git commit -am "s15"
$ git checkout -b experiment
$ echo exp1 >> 1.txt
$ git commit -am "e1"
$ git checkout server
$ echo ser5 >> 1.txt
$ git commit -am "s16"
$ git checkout master
$ git merge server
$ git checkout experiment
$ git rebase master
# будут конфликты, решаем их
$ git mergetool
$ git rebase --continue
$ gitk --all

QytqLXY.png

D
DancingOnWater, 2014-01-20
@DancingOnWater

Remember that ALL branches in git are equal and the term inherited from this or that is not correct.
Another thing to remember is that git operates on project states. And on the one hand, commit - stores the delta of the state, and on the other hand, the entire state as a whole.
Now let's ask the question differently, shall we?
1) Experiment branch - what is it? A side branch in which work is being done on a separate feature?
Then there is no point in updating the experiment branch. And it is better to use at the end of the experiments to merge the branch with the master using merge.
2) This branch is a branch where it started on the new version of the product, and does the master contain fixes that should be transferred to the new version? Then the use of patches looks logical.
3) Is parallel, alternative development being carried out in the experiment branch? Then it's better to use rebase, then all your commits will be on top and your development will not be broken

T
tamtakoe, 2014-01-18
@tamtakoe

What will it give in the context of the task?

T
tamtakoe, 2014-01-21
@tamtakoe

rebase turned out to be what you need. Although, I have no idea how to do this with patches. It might be easy for them too.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question