I'm familiar with ClearCase where we can merge a file to a branch from any other branch. How is this possible in git? For eg, I have the following structure
master--->branch_2
|
|
V
branch_1
So there is some independent development going in branch_1
and branch_2
. I want to merge some specific code from branch_2
to branch_1
using some mergetool like kdiff3.
EDIT: Kdiff3 has an awesome merging option by comparing 2 or 3 versions of the file (from same or different branch), highlighting the conflicts. Then we can jump through each conflict, and pick the code from 1 or more versions of the file, make some edits (if necessary) and finally save the file. This feature has been quite handy for me when I worked with ClearCase. Is there a way to configure git mergetool with kdiff3 to work the same way?
Thanks in advance
It sounds like you want to merge a specific portion of changes from a given commit in branch_2
.
If that's the case, you can use git cherry-pick --no-commit
or (-n
) to apply the changes from a commit in branch_2
without creating a new commit. From that point you can decide which changes to commit by staging only portions of the modified files.
Here's an example:
git checkout branch_1
git cherry-pick -n <some-commit> # 1. Apply the changes from some commit in branch_2
# without creating a new commit
git reset HEAD # 2. Unstage all changes from that commit
git add -p # 3. Decide which changes to include in the commit
git commit # 4. Commit those changes