我如何从Git的开发者变成大师者获得最后的合并? [英] How do I get the last merge from develop into master in Git?

查看:162
本文介绍了我如何从Git的开发者变成大师者获得最后的合并?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了自动执行配置项,我需要从 develop 分支到 master 分支(或更一般而言,从给定的源分支到给定的目标分支). 我尝试过

In order to automate my CI, I need to get the info of the last merge executed from the develop branch into the master branch (or more generically, from a given source branch to a given destination branch). I tried with

git log --oneline --merges  master -20

但是,这为我提供了所有最近20个合并到 master 的列表,而没有按源分支进行区分(让我省去了繁琐的任务来从注释中解析和推断源分支). 是否有一种干净且健壮的方法可以直接从命令行通过源分支进行过滤?

but this get me a list of all the last 20 merges into master, without differentiating by source branch (leaving me with the cumbersome task to parse and infer the source branch from the comment). Is there a clean and robust way to filter by source branch directly from the command line ?

注意:我不需要,需要与CI或分支机构管理最佳做法有关的建议.我们在内部使用GitFlow工作流程( https://www.atlassian.com /git/tutorials/comparing-workflows/gitflow-workflow ),因此与存储库/CI相关的所有内容都已经处于完美的顺序(从方法论上来说).我只需要一个非常具体回答,一个非常具体的问题,谢谢!

Note: I do not need for suggestions related to CI or branch-management best practices. We internally use the GitFlow workflow (https://www.atlassian.com/git/tutorials/comparing-workflows/gitflow-workflow), so everything repository/CI-related is already in perfect order (methodologically speaking). I just need for a very specific answer to a very specific question, thanks !

推荐答案

有没有一种方法可以直接从命令行按源分支进行过滤?

Is there a way to filter by source branch directly from the command line?

不. Git中的分支只是标签.合并不记得它们合并到的分支或来自哪个分支,它们只记住其父提交和提交消息.合并后,两个历史都将成为分支的一部分.

No. Branches in Git are just labels. Merges don't remember what branch they were merged to nor from, they only remember their parent commits and commit messages. Once merged both histories are equally part of the branch.

这些都是同一存储库的不同视图.

These are both different views of the same repository.

      < C <-- D <---- I [develop]
     /         \     /
A < B < E < F < G < H [master]

              <------ I [develop]
             /       /
A < B < C < D < G < H [master]
     \         /
      E <--- F

除我以外的所有提交都属于master分支(即,可以从H到达它们).所有提交都是develop分支的一部分(即,可以从I到达它们). G是来自develop还是来自不相关分支的合并?从拓扑上讲,没有办法.

All commits except I are part of the master branch (ie. they can be reached from H). All commits are part of the develop branch (ie. they can be reached from I). Was G a merge from develop or from an unrelated branch? Topologically there is no way to tell.

最好的办法是希望尝试从合并提交消息和历史记录中推断出信息.如果您的合并提交消息是一致的,那么您也许可以摆脱类似的情况,但是它很脆弱.

Best you can do is hope try to deduce the information from the merge commit message and history. If your merge commit messages are consistent, you might be able to get away with something like this, but it is fragile.

git log --oneline --merges <destination> | grep "Merge branch '<source>'"

这篇关于我如何从Git的开发者变成大师者获得最后的合并?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆