git 进阶 patch 操作

发布时间:2022-06-26 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了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 HEADN 是git rev-list --count的输出结果.

 

3. 进行合并

git apply --check

  git-apply - Apply a patch to files and/or to the index

   

 

  

 

 4. 测试

 

 

脚本宝典总结

以上是脚本宝典为你收集整理的git 进阶 patch 操作全部内容,希望文章能够帮你解决git 进阶 patch 操作所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: