简体   繁体   English

git-远程分支“显然”未删除

[英]git - remote branch “apparently” not deleted

Developer A creates remote branch 开发人员A创建远程分支

git checkout -b myBranch
git push -u origin myBranch

Developer B checks it out 开发者B签出

git fetch origin myBranch
git checkout myBranch

They both do some work, commit, pull, etc. When they are done, merge back to develop 他们都做一些工作,例如提交,拉取等。完成后,合并回去进行开发

git checkout develop
git merge --no-ff myBranch
git push origin develop

and delete branch 并删除分支

# Developer A
git branch -d myBranch             # delete local branch
git push origin --delete myBranch  # delete remote branch

# Developer B
git branch -d myBranch
git fetch

At this point, only Developer A who pushed the remote delete can see the correct state of remote. 此时,只有推送了远程删除的开发人员A才能看到正确的远程状态。 Developer B still sees that myBranch on remote, even though it no longer exists. 即使不再存在myBranch,开发人员B仍然可以看到它在远程上。 If Developer B tries to check out myBranch and pull, gets a 'cannot find myBranch ref' error. 如果开发人员B尝试检出myBranch并提取,则会出现“找不到myBranch引用”错误。

#Developer A
git branch -a
  * develop
  remotes/origin/HEAD -> origin/develop
  remotes/origin/develop
  remotes/origin/production

#Developer B
git branch -a
  * develop
  remotes/origin/myBranch                 # <<<<< why is this line here??
  remotes/origin/HEAD -> origin/develop
  remotes/origin/develop
  remotes/origin/production

If we go on bitBucket web console and look at the repo, branch 'myBranch' does not exist. 如果我们在bitBucket Web控制台上查看仓库,则分支“ myBranch”不存在。

What's going on here and why, how do we solve it? 这是怎么回事,为什么,我们怎么解决呢?

git branch -a git分支-a

-a stand for all branches (local + remote) this is why the user see all the branches. -a代表所有分支(本地+远程),这就是为什么用户看到所有分支的原因。

Developer B still sees that myBranch on remote, even though it no longer exists 即使不再存在myBranch,开发人员B仍然可以看到它在远程

You should execute: git fetch --all --prune 您应该执行: git fetch --all --prune
The prune will remove all local copies of your branches, tags which are removed from the server. 修剪将删除分支的所有本地副本,这些副本将从服务器中删除。


You can set the prune value to be your default so it will remove the deleted branches and tags on every fetch 您可以将剪枝值设置为默认值,这样它将在每次获取时删除已删除的分支和标记。

git config fetch.prune true

-p / --prune -p /-修剪

After fetching, remove any remote-tracking references that no longer exist on the remote. 提取后,删除远程上不再存在的所有远程跟踪引用。

Tags are not subject to pruning if they are fetched only because of the default tag auto-following or due to a - -tag option. 如果仅由于默认标签自动跟随或由于-tag选项而获取标签,则不对它们进行修剪。

However, if tags are fetched due to an explicit refspec (either on the command line or in the remote configuration, for example if the remote was cloned with the --mirror option), then they are also subject to pruning . 但是,如果由于显式的refspec(在命令行或在远程配置中,例如,如果使用--mirror选项克隆了远程服务器)而获取了标记,则也将对其进行修剪

Developer B needs to use the -p parameter on git fetch. 开发人员B需要在git fetch上使用-p参数。 git fetch -p This parameter will remove all references that do not exist on remote. git fetch -p此参数将删除远程上不存在的所有引用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM