GIT: how to make a partial merge from one branch to another?

I made ABCD on one branch and want to combine ABC with another.

I know that you could make git cherry picks one by one, and my question is if I can combine these commits together and hopefully make squash.

+5
source share
6 answers

Like Autocracy , git rebase is probably what you want.

Example:

Say you have A-B-C-Dand you want to combine A-B-Cin Y. Creates a clone Cand reloads the clone to Y:

git checkout -b C_copy C
git rebase --onto Y A~1 C_copy  # <= --onto [target] [source] [what]

Check to see if everything went well and resolved conflicts in your way, if necessary.

C_copy Y, : Y-[A_copy]-[B-copy]-C_copy

rebase, . ( C_copy):

git rebase -i HEAD~3

- , C_copy, C.

Y C_copy git merge --no-ff ( --no-commit, , ):

git checkout Y
git merge --no-ff [--no-commit] C_copy
+8

git checkout branch-to-merge-on; git merge tag-or-sha1-of-commit-c?

, :

git init
touch init; git add init; git commit -m 'init'
git checkout -b abcd
touch a; git add a; git commit -m 'a'
touch b; git add b; git commit -m 'b'
touch c; git add c; git commit -m 'c'; git tag commit-c
touch d; git add d; git commit -m 'd'
git checkout master
touch e; git add e; git commit -m 'e'
git merge commit-c

init -- e -- merged   <- (master)
 \           /   
  a -- b -- c -- d    <- (abcd)

( (init) ) , , , . , git rebase a-b-c-d .

+2

git branch featureX C
git checkout branch_to_merge_to
git merge featureX

--squash , .

, A . , .

, .

+2

wnoise git rebase .

init -- e --  a -- b -- c (merged)   <- (master)
  \                    /
   \             -----
    \           /   
     a -- b -- c -- d    <- (abcd)

"a" , :

git rebase -i init

init -- e -- b -- c (merged)   <- (master)
+1

git rebase -i. , . , , , .

0

git cherry-pick --no-commit A B C, .

0

All Articles