[英]Why does git branch --merged not show all merged branches?
I created a feature branch, then created a PR for it.我创建了一个功能分支,然后为它创建了一个 PR。 My PR was accepted and merged.
我的 PR 被接受并合并了。 The PR says, "the branch can be safely deleted."
PR 说,“可以安全地删除分支。” But when I do
git branch --merged
on the main branch, I don't see the merged branch.但是当我在主分支上执行
git branch --merged
时,我没有看到合并的分支。 What I am doing wrong?我做错了什么?
This is a difficult question to answer without knowing the exact workflow.如果不知道确切的工作流程,这是一个很难回答的问题。
I assume since you 'created a PR' you forked/cloned a non-local repo to start with.我假设自从你“创建了一个 PR”,你就分叉/克隆了一个非本地存储库。 Then you created a new branch in your local repository, made changes to add a feature, and committed those changes onto your local feature branch.
然后,您在本地存储库中创建了一个新分支,进行了更改以添加功能,并将这些更改提交到您的本地功能分支。
Beyond that it's a bit murkier.除此之外,它有点模糊。 Here are a few steps you might take:
以下是您可能采取的几个步骤:
You say you submitted a PR, but you don't say that you ever merged the feature branch with your local master branch.你说你提交了一个 PR,但你并没有说你曾经将功能分支与本地主分支合并。 That suggests you may be following a workflow like this one .
这表明你可能会下一个工作流程像这样的。 If that's the case, and you're running
git branch --merged
in your local repository, the reason you don't see your feature branch listed is that you never merged your feature branch into master in your local repository.如果是这种情况,并且您在本地存储库中运行
git branch --merged
,那么您没有看到列出的功能分支的原因是您从未将功能分支合并到本地存储库中的master 。 This, IMO, is the most likely scenario. IMO,这是最有可能的情况。 Try running
git pull <name of your remote--probably origin> master
from your local master branch, then trying running git branch --merged
again.尝试从本地主分支运行
git pull <name of your remote--probably origin> master
,然后再次尝试运行git branch --merged
。
Fast-forwarding could cause some confusion, though it wouldn't create the issue you're describing on its own. 快进可能会引起一些混乱,但它本身不会造成您所描述的问题。
You can always run git log
on a given branch to see its full commit history.您始终可以在给定分支上运行
git log
以查看其完整的提交历史记录。 You could examine the commit history of your master and compare it to the commit history of origin/master to maybe find the discrepancy.您可以检查 master 的提交历史并将其与 origin/master 的提交历史进行比较,以找出差异。
Hope this helps!希望这可以帮助!
I have been struggling with this also.我也一直在为此苦苦挣扎。 We are using gitlab's MR flow , which is probably the most simple merge based git flow.
我们正在使用gitlab 的 MR flow ,这可能是最简单的基于合并的 git flow。
What I have noticed is that we select to Squash Commits when a MR is merged.我注意到的是,当 MR 合并时,我们选择Squash Commits 。 As a consequence this affects git history and prevents the
--merged
flag from working as expected.因此,这会影响 git 历史记录并阻止
--merged
标志按预期工作。
I had similar problem, when feature branches were merged to develop and develop was merged to master.我有类似的问题,当功能分支被合并到开发和开发被合并到主。 Such branches are not shown for
此类分支未显示
git branch --merged master,
but shown for
git branch --merged develop
But it's better to use -r flag as recommended in How can I delete all Git branches which have been merged?但是最好按照如何删除所有已合并的 Git 分支中的建议使用 -r 标志。
Remote git clear:远程 git 清除:
git branch -r --merged | grep -v '\*\|master\|develop\|release' | sed 's/origin\///'
| xargs -n 1 git push --delete origin
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.