git 使用已删除的远程分支从原点获取?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5751582/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 10:43:07  来源:igfitidea点击:

fetch from origin with deleted remote branches?

gitgit-fetch

提问by Chris Muench

When I do git fetch originand origin has a deleted branch, it doesn't seem to update it in my repository. When I do git branch -rit still shows origin/DELETED_BRANCH.

当我这样做git fetch origin并且 origin 有一个已删除的分支时,它似乎没有在我的存储库中更新它。当我这样做时,git branch -r它仍然显示origin/DELETED_BRANCH.

How can I fix this?

我怎样才能解决这个问题?

回答by Pavan Yalamanchili

You need to do the following

您需要执行以下操作

git fetch -p

This will update the local database of remote branches.

这将更新远程分支的本地数据库。

回答by Chris Muench

From http://www.gitguys.com/topics/adding-and-removing-remote-branches/

来自http://www.gitguys.com/topics/adding-and-removing-remote-branches/

After someone deletes a branch from a remote repository, git will not automatically delete the local repository branches when a user does a git pull or git fetch. However, if the user would like to have all tracking branches removed from their local repository that have been deleted in a remote repository, they can type:

git remote prune origin

当有人从远程仓库中删除一个分支后,当用户执行 git pull 或 git fetch 时,git 不会自动删除本地仓库分支。但是,如果用户希望从远程存储库中删除的本地存储库中删除所有跟踪分支,他们可以键入:

git远程修剪起源

As a note, the -p param from git fetch -pactually means "prune".
Either way you chose, the non-existing remote branches will be deleted from your local repository.

需要注意的是, -p 参数 fromgit fetch -p实际上意味着“修剪”。
无论您选择哪种方式,不存在的远程分支都将从您的本地存储库中删除。

回答by naXa

You need to do the following

您需要执行以下操作

git fetch -p

in order to synchronize your branch list. The git manualsays

为了同步您的分支列表。在git的手册

-p, --prune
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 --tagsoption. 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 --mirroroption), then they are also subject to pruning.

-p,--prune
获取后,删除遥控器上不再存在的任何远程跟踪引用。如果标签仅由于默认标签自动跟随或由于--tags选项而被提取,则标签不会受到修剪。但是,如果由于明确的 refspec(在命令行上或在远程配置中,例如,如果远程是使用--mirror选项克隆的)而获取标签,则它们也将受到修剪。

I personally like to use git fetch origin -p --progressbecause it shows a progress indicator.

我个人喜欢使用,git fetch origin -p --progress因为它显示了一个进度指示器。

回答by Antstud

This worked for me.

这对我有用。

git remote update --prune

回答by VonC

Regarding git fetch -p, its behavior changed in Git 1.9, and only Git 2.9.x/2.10 reflects that.

关于git fetch -p,它的行为在 Git 1.9 中发生了变化,只有 Git 2.9.x/2.10 反映了这一点。

See commit 9e70233(13 Jun 2016) by Jeff King (peff).
(Merged by Junio C Hamano -- gitster--in commit 1c22105, 06 Jul 2016)

请参阅Jeff King ( ) 的提交 9e70233(2016 年 6 月 13 日(由Junio C Hamano合并-- --commit 1c22105,2016 年 7 月 6 日)peff
gitster

fetch: document that pruning happens beforefetching

This was changed in 10a6cc8(fetch --prune: Run prune before fetching, 2014-01-02), but it seems that nobody in that discussion realized we were advertising the "after" explicitly.

fetch: 记录获取之前发生修剪

这在10a6cc8( fetch --prune: Run prune before fetching, 2014-01-02)中有所改变,但似乎在那次讨论中没有人意识到我们在明确宣传“after”。

So the documentation now states:

所以文档现在指出:

Beforefetching, remove any remote-tracking references that no longer exist on the remote

获取之前,删除远程上不再存在的任何远程跟踪引用

That is because:

那是因为:

When we have a remote-tracking branch named "frotz/nitfol" from a previous fetch, and the upstream now has a branch named "frotz", fetch would fail to remove "frotz/nitfol" with a "git fetch --prune" from the upstream. git would inform the user to use "git remote prune" to fix the problem.

Change the way "fetch --prune" works by moving the pruning operation before the fetching operation. This way, instead of warning the user of a conflict, it automatically fixes it.

当我们有一个名为“ frotz/nitfol”的远程跟踪分支来自先前的 fetch 时,上游现在有一个名为“ frotz”的分支,fetch 将无法从上游删除frotz/nitfol带有“ git fetch --prune”的“ ”。git 会通知用户使用“ git remote prune”来解决问题。

fetch --prune通过在获取操作之前移动修剪操作来改变“ ”的工作方式。这样,它不会警告用户发生冲突,而是自动修复它。