问题描述
我想自动清理远程分支机构。我希望能够检查一个分支是否已经被合并到master中。最初,我的计划是使用git merge-base来查看最后的常见提交。然而,事实证明,我们压缩了我们所有的分支,因为我们将它们合并到了主分支中。由于这会创建一个新的提交散列,因此我无法在主分支和我的分支之间找到常见提交。
如何确定分支是否已合并如果我们在合并时压缩了它们全部?
预先感谢!
您可以进行一次试验性合并,并检查它是否引入了任何更改,如下所示:
git checkout -b foo -merge-test-branch master
git merge --squash foo
if [-n$(git status --porcelain)];那么
回显foo尚未合并;
else
echofoo已经合并;
fi
git reset --hard&& git checkout master&& git branch -d foo-merge-test-branch
只有当这些文件都没有改变在原来的 git merge --squash foo
之后,在 master
上看到了进一步的冲突。
I'd like to automate cleaning of remote branches. I want to be able to check to see if a branch has been merged into master already. Originally, my plan was to use git merge-base to see the last common commit.
However, it turns out that we squash all of our branches as we merge them into master. As this creates a new commit hash, I'm unable to find the common commits between master and my branches.
How might I go about determining if a branch has been merged if we've squashed them all when merging?
Thanks in advance!
You could do an experimental merge and check whether it introduces any changes, like so:
git checkout -b foo-merge-test-branch master
git merge --squash foo
if [ -n "$(git status --porcelain)" ]; then
echo "foo has not been merged";
else
echo "foo is already merged";
fi
git reset --hard && git checkout master && git branch -d foo-merge-test-branch
This will only work if none of the files changed in the original git merge --squash foo
have seen further conflicting changes on master
since then.
这篇关于SQUASHED时检查Git分支是否已合并到主控中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!