A
A
Artyom Zubkov2011-02-10 12:27:24
git
Artyom Zubkov, 2011-02-10 12:27:24

Merging 2 Git branches?

Hi all!
Given:
1. Git repository.
2. A project that has 2 branches:

v2 - changes in 3 files have been made and committed. Suppose that in the first it is line 10, in the second 5, in the third 6.
master - changes have been made in the same 3 files in the same lines, but they are also needed.
3. Merge conflict between master and v2.
Task:
1. How to resolve the conflict?
2. Is there a way to take the changes from v2 only from the lines and files of interest and apply them to master

Answer the question

In order to leave comments, you need to log in

3 answer(s)
V
VlK, 2011-02-10
@artzub

Correct in your case would be
1) git rebase master
from the aux branch. Probably the step involves resolving possible conflicts.
2) git rebase -i HEAD^^^
from the aux branch. We collect several secondary branch commits into one (optional, but often required for accurate commits)
3) git merge secondary-branch --ff-only
from the main branch. Fast-forward merging (that is, without resolving conflicts) new commits from the auxiliary branch
. That is, you first make changes from the main to the auxiliary branch, and then include the new commits from the auxiliary to the main branch.
Sometimes it makes sense to git rebase -i a sub branch on itself to merge a number of commits into one.
In short. It's good practice not to have merge commits on the master branch.

W
whitequark, 2011-02-10
@whitequark

Alas, if git could not resolve the conflict itself, then it cannot be done automatically automatically.
You can grab only the changes you want by simply copying the v2 tree on top of the master tree and then writing only the changes you want with git add --interactive. Anything not needed is then removed via git checkout ., which will reset the state of the working directory to the index (anything added via git addwill remain).

I
Ivan Filatov, 2011-02-10
@NYMEZIDE

everything can be done through diff
, run, compare, choose what to take and from where.
there is even a graphical shell included in TourtoisGIT

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question