git 进阶 patch 操作
场景:
一个项目,两个分支。
1. 社区分支 没有接受 本地分支 代码。
2. 本地分支依赖社区分支。
3.社区有版本更新时,需要将本地分支的代码合并到 社区release 分支。 这里主要介绍此方法。
Branch A: (Community)
startA <- c0 <- c1 <- c2 <- c3 ...
Branch B: (Local) |
startB <- c0 <- c1 <- c2' <- c3' ..
方法大纲:
1.获取Branch B分支中的从c2'开始的所有提交。
2.将这些提交转变成patch.
3.在Brach A上进行apply patch. (如果冲突,进行手动合并)
1. git rev-list (计算从c2'开始的提交数量)
用处: 选择区间内的commits
语法: git rev-list [<options>] <commit>… [[--] <path>…]
DESCRIPTION
List commits that are reachable by following the parent
links from the given commit(s), but exclude commits that are reachable from the one(s) given with a ^ in front of them. The output is given in reverse chronological order by default.
You can think of this as a set operation. Commits reachable from any of the commits given on the command line form a set, and then commits reachable from any of the ones given with ^ in front are subtracted from that set. The remaining commits are what comes out in the command’s output. Various other options and paths parameters can be used to further limit the result.
$ git rev-list foo ^baz means "list all the commits which are reachable from foo ,but not from baz".
foo <- commit0 <- commit1 <- ... HEAD
A <- B, A is parent of B.
git rev-list --count 命令
git rev-list --count $(git log -a | egrep "comment " -B4 | grep commit | awk '{print $2}')…HEAD
2. Generate Patchs
git format-patch -N HEAD
N 是git rev-list --count的输出结果.
3. 进行合并
git apply --check
git-apply - Apply a patch to files and/or to the index
4. 测试