Dre*_*nai 60 github visual-studio visual-studio-code
在VSCode中,在我执行拉取请求并删除GitHub上的分支后,该分支仍然显示在Visual Studio代码中.如果我选择分支,它会按预期给出错误.
如何从VSCode中删除这些现已删除的分支 - 我可以自动执行吗?
列出并删除多个分支
与此同时__CODE__,这是我用于的另一个分支删除相关命令__CODE__:
示例 - 列出以.开头的所有分支 __CODE__
__PRE__
列表删除.注意:更换__CODE__与__CODE__删除没有警告
__PRE__
dav*_*000 99
显然,这个功能是有意的.我发现删除从Github删除的所有远程分支的正确方法是运行以下命令.
git fetch --prune
Run Code Online (Sandbox Code Playgroud)
然后重新启动visual studio以从命令选项板中删除分支
小智 41
通过打开Command Pallete(Ctrl-Shift-P)然后选择Git:Delete Branch ...,可以从Visual Studio Code中删除本地分支,然后可以通过从列表中选择适当的分支来删除本地分支.
Krz*_*lak 12
从GitHub中删除的分支很好......刚从GitHub中删除.您的计算机上仍有本地分支副本.删除本地分支运行git branch -d the_local_branch.VS Code中没有命令可以执行此操作,但您可以使用View: Toggle Integrated Terminal命令和运行命令在VSCode中启动终端.
有关分支机构管理的更多信息,请访问git文档 - https://git-scm.com/book/be/v2/Git-Branching-Branch-Management
您需要做的就是运行以下命令:
git remote prune origin
Run Code Online (Sandbox Code Playgroud)
您可以做一些额外的事情,因为有时为此打开终端很烦人..您可以在 vscode 中添加一个任务。
为此,请按照以下步骤操作:
{ "label": "Git Prune", "type": "shell", "command": "git remote prune origin", "problemMatcher": [] }
如何使用它:
参考:
我找到了解决这个问题的方法。因此,您需要删除链接到 Github 存储库的遥控器,然后再次添加该遥控器。
所有从 Github 删除的分支将不再显示在 vscode 中。假设这origin是远程存储库的名称。
git remote remove origin
Run Code Online (Sandbox Code Playgroud)
然后
git remote add origin git@github.com:your-username/repo-name.git
Run Code Online (Sandbox Code Playgroud)
I interpreted the question to be: how can I delete my local branches that have been merged, since I've been using Git Fetch (Prune) from the command palette. This may be considered a "hack", but it's what I use. In the PowerShell terminal:
$branches = (git branch --merged).replace(" ", "").replace("*", "") | ? { $_ -ne "develop" -and $_ -ne "master" }
foreach ($branch in $branches) { git branch $branch -d }
Run Code Online (Sandbox Code Playgroud)
In case you're not familiar with PoSH, here's what that does: the first line gets the name of all merged branches (with the exception of develop and master), and the second line loops through that list and runs "git branch -d". As long as the branch is merged completely, you should see:
Deleted branch <branch name> (was <commit ID>).
Run Code Online (Sandbox Code Playgroud)
for each branch. Occasionally I'll run into a branch that fails to be deleted - if this happens, and you're sure that it's safe to be deleted (i.e. you won't lose local work that hasn't been stored), you can run:
git branch <branch name> -D
Run Code Online (Sandbox Code Playgroud)
Note the capital D - that forcibly deletes the local branch.
您可以使用以下命令删除所有本地分支(主分支除外):
git branch -r | grep -v "master" | xargs git branch -D
Run Code Online (Sandbox Code Playgroud)
您可以删除所有仍然出现origin/XXXX在 VSCode 中但已删除的分支origin:
git fetch --prune
Run Code Online (Sandbox Code Playgroud)
笔记:
上面的第一个命令(取自/sf/answers/3640438931/):
您不必再git fetch --prune重新启动 VSCode。
使用 VSCode 1.52(2020 年 11 月),您现在拥有:
Git:在获取时修剪
启用该
git.pruneOnFetch设置将使 VS Codegit fetch --prune在获取远程引用时运行。
一旦从 GitHub 中删除它们,本地就不再有额外的分支。
用法:
Run Code Online (Sandbox Code Playgroud){ "git.pruneOnFetch": true }设置为
false默认。这会将
--prune标志添加到所有 git fetches。
| 归档时间: |
|
| 查看次数: |
34686 次 |
| 最近记录: |