如何检测在远程删除的合并分支 [英] How to detect merged branches that were deleted in remote

查看:76
本文介绍了如何检测在远程删除的合并分支的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Git,并且试图将本地分支与远程分支同步.我总是在本地和远程存储库中保留一个主"分支和一个开发"分支.创建新功能时,会为其创建一个分支并命名为:feature/my-new-feature-name.

I'm using Git and I'm trying to sync up my local branches with remote ones. I always keep a "master" and a "develop" branches in both local and remote repositories. When I create a new feature, I create a branch for it and name it like this: feature/my-new-feature-name.

完成该功能后,我将所有更改提交并推送到远程存储库(我将Gitlab用于我的远程存储库).然后,我将功能分支合并到开发分支,并使用Gi​​tLab接口删除源分支(功能分支).此时,该功能已合并到developer分支中,仅在远程存储库中删除.

When I finish working on the feature, I commit and push all changes to remote repository (I use Gitlab for my remote repo). Then I merge the feature branch into develop branch and delete the source branch (the feature branch) using GitLab interface. At this point, the feature was merged into develop branch and deleted only in remote repository.

完成这些步骤后,我希望能够将本地分支同步到远程分支的状态.也就是说,我想将我的功能分支合并到开发中,并从本地存储库中删除.

After these steps, I wanna be able to sync my local branch to the state my remote branch is. That is, I wanna have my feature branch merged into develop and deleted from local repo.

为此,我运行以下命令:

To do this, I run the following commands:

git checkout develop
git pull
git branch -d feature/my-new-feature-name

当我这样做时,Git会向我显示以下消息:

When I do this, Git shows me this message:

error: The branch 'feature/my-new-feature-name' is not fully merged.
If you are sure you want to delete it, run 'git branch -D feature/my-new-feature-name'.

我当然可以使用-D标志运行命令,但是我想理解为什么Git表示分支没有合并.

Of course I can just run the command using -D flag, but I wanna understand why Git says the branch is not merged.

我在Stack Overflow中发现了有关此问题的几个问题,但是在所有这些问题中,人们建议运行此命令以检查合并的分支: git branch --merged

I found several questions about this in Stack Overflow, but in all of them people suggest running this command in order to check the merged branches: git branch --merged

当我运行此命令时,Git仅向我显示dev分支,好像没有合并feature/my-new-feature-name一样.但是实际上,feature/my-new-feature-name被合并(在远程回购中)并拉到本地.我还可以通过运行git log来查看我的合并提交.为什么Git不能检测到我的功能分支已合并到开发中?

When I run this command Git shows me only the develop branch, as if feature/my-new-feature-name was not merged. But in fact feature/my-new-feature-name was merged (in remote repo) and pulled to local one. I can also see my merge commit by running git log. Why does Git doesn't detect my feature branch as merged into develop?

推荐答案

问题是合并时将南瓜标志设置为true.如果您不合并,Git只会检测到合并.

The problem was to set the squash flag to true when merging. Git only detects the merge if you merge without squash.

这篇关于如何检测在远程删除的合并分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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