当其工作目录被删除时如何删除一个git工作树分支? [英] How to delete a git working tree branch when its working directory has been removed?

查看:984
本文介绍了当其工作目录被删除时如何删除一个git工作树分支?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经删除了它的工作目录,因为这个git工作树不再有用,于是我在主目录下 git branch -D pubsub-sketch-tree 库。抛出一个错误:

 错误:无法删除分支 '发布 - 订阅素描树' 在/用户签出/ zhouhancheng /编程/ github_own / sketch_worktree /发布订阅-sketch_tree '

但是,'/用户/ zhouhancheng /编程/ github_own / sketch_worktree / pubsub-sketch_tree'已被删除。 所述 GIT中worktree 文档:


当您完成链接工作树时,您可以简单地将其删除。资源库中的工作树的管理文件(见下面的 详细信息)最终将被自动删除(请参阅 gc.worktreePruneExpire 中的 git-config(1))或者 你可以运行 git worktree prune 来清除所有过时的管理文件。




(强调我的)。如果Git认为它在第二工作树中检出,Git不会让你删除该分支。如果第二个工作树已经被删除,但Git还没有注意到这一点,那么运行 git worktree prune 告诉 Git去检查。


I've removed its working directory, because this git working tree is no longer useful, then I git branch -D pubsub-sketch-tree at the directory of main repository. An error thrown:

error: Cannot delete branch 'pubsub-sketch-tree' checked out at '/Users/zhouhancheng/编程/github_own/sketch_worktree/pubsub-sketch_tree'  

But '/Users/zhouhancheng/编程/github_own/sketch_worktree/pubsub-sketch_tree' had been removed.

解决方案

You are using git worktree, so the answer is in the git worktree documentation:

When you are done with a linked working tree you can simply delete it. The working tree’s administrative files in the repository (see "DETAILS" below) will eventually be removed automatically (see gc.worktreePruneExpire in git-config(1)), or you can run git worktree prune in the main or any linked working tree to clean up any stale administrative files.

(emphasis mine). Git won't let you delete the branch if it believes it is checked out in a secondary worktree. If the secondary worktree is already removed, but Git has not yet caught on to that fact, just run git worktree prune to tell Git to go check.

这篇关于当其工作目录被删除时如何删除一个git工作树分支?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆