There are now two branches, namely branch A and branch B. There are several submissions on each branch;
The commits of branch A include a1, a2, a3, a4, a5, a total of five submissions;
The commits of branch B include b1, b2, b3, b4, b5, there are five submissions in total;
is currently on branch A.
Note: The hash values of the above 10 submissions are different.
Excuse me: How can I only pull the b2, b3, and b4 commit nodes of branch B to branch A?
Requires that after pulling to branch A, the original commit information on branch B must be retained.
Please break ╮( ̄▽  ̄)╭ ~
The cherry-pick
method mentioned by @junnplus is correct, and I can do it too; but is there a better answer?
黄舟2017-05-02 09:34:03
If automation is not required, the most convenient way is this:
$ git rebase -i HEAD $name_of_branch_b
The editor will display five lines from b1 to b5, delete the two lines b1 and b5, save and exit.
过去多啦不再A梦2017-05-02 09:34:03
It may be difficult to have a better answer, right? According to the git-flow
的原则,dev-feature
一般不会有只合并中间几次提交到dev
divided situation, maybe the subject's need is based on unreasonable version management strategy or very special scenarios.
淡淡烟草味2017-05-02 09:34:03
Everyone is right, there is no good way; but I still have this special need in my actual work process.
Tonight I used my poor shell programming skills to write a program that can achieve my needs, and it can be achieved through cherry-pick
.
This small program can fulfill my needs as long as it is executed as follows:
# b5省略时取到最新的节点
cherry-picks B b2 b5
Next is my debut: github link
#!/usr/bin/env bash
# 初始化
targetBranch=
start=
end= #如果没有这读到最新
currentBranch=$(git symbolic-ref HEAD 2>/dev/null | cut -d"/" -f 3)
# 切换到目标分支
git checkout $targetBranch
echo start proccess commit message...
rawList=$(git log | grep '^commit' | sed '1,$s/commit//')
startIndex=$(echo "$rawList" | sed -n "/$start/=" )
# 如果end不为空,取得结束的偏移量,否则默认为1,也就是最新
if [ -n "$end" ]; then
endIndex=$(echo "$rawList" | sed -n "/$end/=")
else
endIndex=1
fi
# 取得需要cherry-pick的区间
list=$(echo "$rawList" | head -$startIndex | tail +$endIndex)
## 倒序
list=$(echo "$list" |sed '1!G;h;$!d')
echo '待cherry-pick的有:'
echo list:
echo "$list"
echo
# 切换回当前分支
git checkout $currentBranch
for i in "$list"; do
git cherry-pick $i
done
echo '完成'
exit 0