简体   繁体   English

为什么Git会在没有抱怨的情况下签出此已删除的分支?

[英]Why does Git checkout this deleted branch without complaining?

I just removed a remote branch from our distant Git repository: 我刚刚从遥远的Git存储库中删除了一个远程分支:

$ git push origin :obsoleteBranch

To git@<path_to_our_git_repo>/our_git_repo.git
 - [deleted]         obsoleteBranch

Now my local copy of obsoleteBranch is now tracking a branch that is "gone": 现在,我的obsoleteBranch本地副本正在跟踪“消失”的分支:

git branch -avv
* obsoleteBranch  dbef4b0 [origin/obsoleteBranch: gone] commit log...

So far, so good! 到现在为止还挺好!

The problem is my colleague still sees the remote branch, even after git fetch --all : 问题是,即使在git fetch --all之后,我的同事仍然看到远程分支:

$ git fetch --all
Fetching origin
......
$ git branch -avv
......
remotes/origin/obsoleteBranch dbef4b0 commit log...
......

Git doesn't complain when my colleague tries to checkout the removed branch! 当我的同事尝试签出已删除的分支时,Git不会抱怨!

$ git checkout --track origin/obsoleteBranch

and actually does the checkout just where the removed branch used to be! 并实际上执行检出操作,该操作仅位于删除的分支曾经所在的位置!

But (proof that the remote branch is actually gone) my colleague cannot delete it: 但是(证明远程分支实际上已经消失了),我的同事无法删除它:

$ git push origin :obsoleteBranch
error: unable to delete 'obsoleteBranch': remote ref does not exist
error: failed to push some refs to 'git@<path...>/our_git_repo.git'

What is going wrong? 怎么了?

Didn't git fetch --all completely synchronize my colleague's repository with the remote repository? git没有获取-全部完全将我同事的存储库与远程存储库同步吗?

What command should he run, then, in order to have his local repository take into account the branch deletion for git branch -avv and git checkout ? 为了使他的本地存储库考虑git branch -avvgit checkout的分支删除,他应该运行什么命令?

git caches info about remote branches. git缓存有关远程分支的信息。 Your colleague must have fetched info about that obsoleteBranch before. 您的同事之前必须已经获取了有关该过时的分支的信息。 That's why he sees it and is able to check out the commit (the commit is also downloaded to his local repo). 这就是为什么他看到它并能够检出提交的原因(该提交也已下载到他的本地仓库中)。

git fetch --all --prune

should remove now-orphaned references to remote branches. 应该删除对远程分支的现在孤立的引用。

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

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