gpt4 book ai didi

git - GitHub如何检查两个分支是否可以自动 merge ?

转载 作者:太空狗 更新时间:2023-10-29 14:16:00 27 4
gpt4 key购买 nike

我在创建 merge 提交之前使用 pygit2(python 的 libgit2 包装器),即与两个 parent 一起提交——我想做一个类似 GitHub 的试运行检查,以确保分支实际上可以自动 merge 。

显而易见的方法是遍历自分支点以来的所有提交,并逐行检查冲突。但我认为(希望?)可能有更好的方法。

最佳答案

我相信,GitHub 通过运行 git merge some_branch 命令并检查返回状态来做到这一点;对于冲突 merge ,git merge 命令返回 1。

$ git merge test1 
Auto-merging HELLO
CONFLICT (content): Merge conflict in HELLO
Automatic merge failed; fix conflicts and then commit the result.
$ echo $?
1

在一次性分支中执行此操作,从将成为 merge 基础的分支中提取。

编辑 merge.verbosity 选项,当设置为“0”时,也可能有一些用处(不确定如何在不脱壳的情况下将其应用于 pygit出):

Controls the amount of output shown by the recursive merge strategy. Level 0 outputs nothing except a final error message if conflicts were detected. Level 1 outputs only conflicts, 2 outputs conflicts and file changes. Level 5 and above outputs debugging information. The default is level 2. Can be overridden by the GIT_MERGE_VERBOSITY environment variable.

参见 git merge 手册页的“配置”部分,地址为 http://linux.die.net/man/1/git-merge .

关于git - GitHub如何检查两个分支是否可以自动 merge ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7437973/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com