使用 Git 时如何刷新 Visual Studio 中的分支(本地/远程)?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33739400/
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
How do I refresh branches (local/remote) in Visual Studio when using Git?
提问by JabberwockyDecompiler
Summary
概括
I am learning how to use Git with Visual Studio. I recently did a pull request where the feature branch was deleted after the merge. The feature branch still shows up in my local and remote branches in Visual Studio. I know how to right click and delete the branch, this is a workaround as others on the team may complete a pull request on a branch that I have without me knowing it. If they delete the branch afterwards I would not know they did so.
我正在学习如何在 Visual Studio 中使用 Git。我最近做了一个拉取请求,其中在合并后删除了功能分支。功能分支仍然显示在 Visual Studio 的本地和远程分支中。我知道如何右键单击并删除分支,这是一种解决方法,因为团队中的其他人可能会在我不知道的情况下在我拥有的分支上完成拉取请求。如果他们之后删除了分支,我将不知道他们这样做了。
Question
题
How do you refresh Visual Studio branches with what is on Git?
如何使用 Git 上的内容刷新 Visual Studio 分支?
What I expect
我期待什么
I would expect a button, link, or right click feature that on click checks for differences, if any are found it asks, "This branch no longer exists, would you like to remove it from Visual Studio?".
我希望有一个按钮、链接或右键单击功能,可以在单击时检查差异,如果发现任何差异,它会询问“此分支不再存在,您想从 Visual Studio 中删除它吗?”。
Tech Specs
技术规格
I am using Visual Studio 2015 Enterprise (still seems to be a symptom of VS 2019)
我正在使用 Visual Studio 2015 Enterprise(似乎仍然是 VS 2019 的症状)
Additional Example
附加示例
This could be another question, but it fits so well here. I just noticed that if I create a branch (say in one VM and look at the same repo with another), Visual Studio does not have a git fetch
option to update the branch list. The refresh button at the top does not seem to do anything. As soon as I run git fetch
in a bash, visual studio has the new branch. I would expect the refresh to take care of this.
这可能是另一个问题,但它非常适合这里。我刚刚注意到,如果我创建一个分支(比如在一个 VM 中查看与另一个 VM 相同的存储库),Visual Studio 没有git fetch
更新分支列表的选项。顶部的刷新按钮似乎没有任何作用。一旦我git fetch
在 bash 中运行,visual studio 就会有新的分支。我希望刷新能解决这个问题。
回答by VonC
If the branch has been deleted on the server side, try in command line (since such a "button" doesn't seem to exist directly in Visual Studio):
如果该分支已在服务器端被删除,请在命令行中尝试(因为 Visual Studio 中似乎不直接存在这样的“按钮”):
git remote prune origin --dry-run
(remove the --dry-run
option to actually delete the local branches)
(去掉--dry-run
实际删除本地分支的选项)
Delete the corresponding local branch as well git branch -d aBranch
.
也删除相应的本地分支git branch -d aBranch
。
Then restart your Visual Studio, and check it picks up the updated branch list. (comments mention you don't have to restart/refresh VS)
然后 重新启动你的 Visual Studio,并检查它是否选取了更新的分支列表。(评论提到您不必重新启动/刷新 VS)
Note: I mentioned before in 2013the configuration
注意:我之前在2013年提到过配置
git config remote.origin.prune true
That would automate that process, and seems to be supported by Visual Studio, as mentioned belowby yaniv.
这将使该过程自动化,并且似乎得到 Visual Studio 的支持,如下面的yaniv 所述。
回答by yaniv
From : https://intovsts.net/2017/01/17/refresh-git-remote-branches-in-visual-studio/
来自:https: //intovsts.net/2017/01/17/refresh-git-remote-branches-in-visual-studio/
You can configure git to do this automatically on fetch/pull running with this command:
您可以将 git 配置为在使用以下命令运行 fetch/pull 时自动执行此操作:
git config remote.origin.prune true –global
Update:
更新:
Visual Studio 2017 version 15.7.3 and above you can do it using the UI :
Visual Studio 2017 版本 15.7.3 及更高版本,您可以使用 UI 执行此操作:
Select Global settings
- Change "Prune remote branches during fetch" to "True"
回答by Thaoden
According to this blog post, you can set a git property via
根据这篇博客文章,您可以通过设置 git 属性
git config remote.origin.prune true
that will remove deleted branches from your list when you perform a fetch.
当您执行提取时,它将从您的列表中删除已删除的分支。
回答by Mark Arnold
VS 2017 appears to have support configurable in Team Explorer:
VS 2017 似乎支持在 Team Explorer 中配置:
Team Explorer Home Settings Git > Global Settings Prune Remote Branches During Fetch: Unset, True, or False
Team Explorer Home Settings Git > Global Settings 在 Fetch 期间修剪远程分支:Unset、True 或 False
回答by lkn2993
You should Unpublish the branchfirst, then others will notice that the branch is unpublished(by trying to pull the branch they will get an error), deleting the local branch is actually a separate process itself and must be done in order to get rid of the branch anyway.
您应该先取消发布分支,然后其他人会注意到该分支未发布(通过尝试拉动分支他们会得到错误),删除本地分支实际上是一个单独的过程本身,必须完成才能摆脱反正分支。