是否有可能确定两个git分支将干净地合并而不影响工作目录? [英] Is it possible to determine if two git branches will merge cleanly without affecting the working directory?

查看:120
本文介绍了是否有可能确定两个git分支将干净地合并而不影响工作目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你可以使用git merge-base来判断是否可以快速前进,但是有一些git技巧可以确定两个分支是否会干净地与某种策略合并而不实际合并?我知道 git merge --no-commit --no-ff $ BRANCH 但是会影响工作目录,我想避免这个工作目录,因为这是一部分web服务。

You can determine with git merge-base if a fast forward is possible, but is there some git trick to determine if two branches will merge cleanly with some strategy without actually doing the merge? I know about git merge --no-commit --no-ff $BRANCH but that affects the working directory, which I'd like to avoid since this is part of a webservice.

推荐答案

没有内置的方法;需要工作树来执行合并。看看合并是否可行(在一般情况下)意味着尝试该策略并看到会发生什么。

There's no built-in way; a work tree is required to perform a merge. Seeing if a merge will work (in the general case) means trying the strategy and seeing what happens.

然而,您可以检查这个微不足道的案例:不要触摸相同的文件。找到合并基础,然后检查 git diff --name-only $ merge_base branchA git diff --name-only $ merge_base branchB 有任何共同点。

You could however check for the trivial case: the two branches don't touch the same files. Find the merge base, and then check if git diff --name-only $merge_base branchA and git diff --name-only $merge_base branchB have anything in common.

否则,您需要一个工作树来尝试合并。您可以轻松创建第二个 - 克隆存储库,或节省空间,只需创建一个工作树。 git-new-workdir 脚本(来自git.git的contrib目录)可以帮助解决这个问题。它会创建一个新的仓库,其 .git 目录中的符号链接已经全部返回到原始仓库。只要注意,在新的工作目录中,您不会修改原始回购检出的分支 - 它们将不同步,就像推入当前检出分支时一样。

Otherwise, you'll need a work tree to try the merge in. You could easily create a second one - either clone the repository, or to save space, just create a work tree. The git-new-workdir script (from git.git's contrib directory) can help with this; it creates a new repo whose .git directory is full of symlinks back to the original one. Just be careful that in that new work directory you don't modify the branch the original repo has checked out - they'll get out of sync, in the same way that pushing into a currently checked out branch messes things up.

这篇关于是否有可能确定两个git分支将干净地合并而不影响工作目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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