本文介绍了如何在创建它们的分支分组的master中找到所有未合并的提交?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须从未合并的分支创建一些代码审查。

I have to create some code review from unmerged branches.

在寻找解决方案时,我们不要去讨论本地分支上下文问题,因为它将在服务器上运行;只会有 origin 远程,我将始终在其他命令之前运行 git fetch origin 命令,当我们谈论分支时,我们将参考 origin / branch-name

In finding solutions, let's not go to local-branch context problem as this will run on a server; there will be just the origin remote, I will always run a git fetch origin command before other commands, and when we talk about branches, we will refer to origin/branch-name.

如果设置很简单,并且每个源自master的分支都以自己的方式继续运行,我们可以运行:

If the setup were simple and each branch that originated from master continued on its own way, we could just run:

git rev-list origin/branch-name --not origin/master --no-merges

每个未合并的分支,并将结果提交添加到每个分支的每个评论中。

for each unmerged branch and add the resulting commits to each review per branch.

问题是当2之间合并时出现的-3个分支,其中一些分支还在继续进行。就像我说的那样,对于每个分支,我都希望以编程方式创建代码评论,并且不想在多个评论中包含提交。

The problem arises when there are merges between 2-3 branches and work is continued on some of them. As I said, for each branch I want to create code reviews programmatic and I don't want to include a commit in multiple reviews.

主要是,减少了查找

或更简单地说...查找所有未合并的提交,这些未合并的提交按创建它们的 分支分组。

Mainly the problems reduce on finding the original branch for each commit.
Or to put it simpler... finding all unmerged commits grouped by the branch they most probably were created on.

让我们关注一个简​​单的例子:

Let's focus on a simple example:

      *    b4 - branch2's head
   *  |    a4 - branch1's head
   |  *    b3
   *  |    merge branch2 into branch1
*  |\ |    m3 - master's head
|  * \|    a3
|  |  |
|  |  *    b2
|  *  |    merge master into branch1
* /|  |    m2
|/ |  *    merge branch1 into branch2
|  * /|    a2
|  |/ |
|  |  *    b1
|  | /
|  |/
| /|
|/ |
|  *       a1
* /        m1
|/
|
*          start

我想要获得的是:


  • 分支1:a1,a2,a3,a4

  • 分支2:b1,b2,b3,b4

我到目前为止发现的最佳解决方案是运行:

The best solution I found so far is to run:

git show-branch --topo-order --topics origin/master origin/branch1 origin/branch2

并分析结果:

* [master] m3
 ! [branch1] a4
  ! [branch2] b4
---
  + [branch2] b4
  + [branch2^] b3
 +  [branch1] a4
 ++ [branch2~2] b2
 -- [branch2~3] Merge branch 'branch1' into branch2
 ++ [branch2~4] b1
 +  [branch1~2] a3
 +  [branch1~4] a2
 ++ [branch1~5] a1
*++ [branch2~5] m1

输出解释如下:


  1. 第一行 n 行是 n 个分支进行了分析

  2. 一行带有----

  3. 每次提交都带有加号(或减号,如果是如果该提交位于第n个分支上,则在第n个缩进字符上合并该提交)。

  4. 最后一行是所有已分析分支的合并基础

  1. First n lines are the n branches analyzed
  2. one line with ----
  3. one line for each commit with a plus (or minus in case of merge commits) on the n-th indentation character if that commit is on the n-th branch.
  4. the last line is the merge base for all branches analyzed

对于第3点,提交名称解析是从一个分支名称开始的,从我所看到的情况来看,该分支对应于在其上创建提交的分支,可能是通过促进第一父级到达的路径。

For point 3. the commit name resolution is starting with a branch name and, from what I see, this branch corresponds to the branch that commits were created on, probably by promoting path reaching by first-parent.

由于我对合并提交不感兴趣,因此我将忽略它们。

As I'm not interested in merge commits, I'll ignore them.

然后我将解析每个分支路径提交以使用rev-parse获得其哈希。

I'll then parse each branch-path-commit to obtain their hash with rev-parse.

我该如何处理这种情况?

How can I handle this situation?

推荐答案

可以使用-mirror 创建一个裸存储库,该存储库可用作原始存储库的镜像,并且可以使用 git remote update --prune 进行更新,之后所有标签都应

The repository could be cloned with --mirror which creates a bare repository that can be used as a mirror of the original repository and can be updated with git remote update --prune after which all the tags should be deleted for this feature.

我是这样实现的:

1.获取未合并到主分支的分支列表

I implement it this way:
1. get a list of branches not merged into master

git branch --no-merged master

2。对于每个分支,请获取该分支而不是主分支的修订列表

2. for each branch get a list of revisions on that branch and not in master branch

git rev-list branch1 --not master --no-merges

如果列表为空,则从分支列表中删除该分支

3.对于每个修订版本,请使用

If the list is empty, remove the branch from the list of branches
3. for each revision, determine the original branch with

git name-rev --name-only revisionHash1

并匹配正则表达式为 ^([^ \〜\ ^] * )([\〜\ ^]。*)?$ 。第一个模式是分支名称,第二个模式是分支的相对路径。

如果找到的分支名称不等于初始分支,则从列表中删除修订。

and match regex for ^([^\~\^]*)([\~\^].*)?$. The first pattern is the branch name, the second is the relative path to the branch.
If the branch name found is not equal to the initial branch, remove revision from the list.

最后,我获得了一个分支列表,并为每个分支列出了一份提交列表。

At the end I obtained a list of branches and for each of them a list of commits.

经过进一步的bash研究后,可以使用以下命令一并完成:

After some more bash research, it can be done all in one line with:

git rev-list --all --not master --no-merges | xargs -L1 git name-rev | grep -oE '[0-9a-f]{40}\s[^\~\^]*'

结果是以下形式的输出

hash branch

可以读取,解析,排序,分组等。

which can be read, parsed, ordered, group or whatever.

这篇关于如何在创建它们的分支分组的master中找到所有未合并的提交?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-11 05:35