Git:有没有办法删除(本地和远程)我创建的所有分支?

发布于 2025-01-18 19:14:55 字数 514 浏览 1 评论 0原文

是否有脚本可以删除我创建的所有分支?

我在Stackoverflow和Internet上找到了有关列出作者列出分支机构的问题,例如

有一个脚本可以列出我创建的git分支?

,但我找不到删除它们的内容。

有什么办法吗?

我还找到了一篇文章,用于未使用的分支批量删除,但没有作者

有没有办法删除git分支?

Is there a script to delete all the branches created by me?

I found questions on stackoverflow and on internet about listing the branches by author, like this

Is there a script to list git branches created by me?

But I could not find anything like delete them.

Is there any way?

I also found one this post for unused branch bulk delete but not by author

Is there a way to bulk delete git branches?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

南烟 2025-01-25 19:14:55

git不知道是谁创建了一些分支名称,所以不,这是不可能的。

我基本上想删除我所有创建的分支,因为它们已合并到父分支

名称也不存储父级信息。但是,您可以询问是否通过某些分支名称找到的提示commit 在中包含在中,通过一些其他分支名称找到的提交集,使用git branch- -Merged例如:

git fetch origin
git branch --merged origin/main

将列出您的任何(本地)存储库分支名称,这些名称识别Origin> Origin's main(如git fet上次更新,因此,git fetch peith tirst tever)。

威廉·普里尔(William Pursell)在评论中问:

当您说“删除分支”时,您只是意味着要删除参考,还是也试图删除提交?

您的答案是:

说实话,我不太确定两者的差异。

这里的区别在于关键,因为git并不是真正关于 branches ,而是关于 consits 。如果您要完全使用git,则必须必须了解提交。这也将使GIT的分支模型有意义。不过,我只会在这里重复所有内容,而是将您引用这个答案

Git has no idea who created some branch name, so no, this is not possible in general.

I basically wants to delete all my created branches because they are merged to the parent branch

Branch names do not store parent information either. You can, however, ask whether the tip commit found via some branch name is contained within the set of commits found via some other branch name, using git branch --merged for instance:

git fetch origin
git branch --merged origin/main

will list out any of your (local) repository branch names that identify a commit that is contained within the commit-set found by origin's main (as last updated by git fetch, hence the git fetch step first).

William Pursell asks, in a comment:

When you say "delete a branch", do you simply mean that you want to delete the ref, or are you also trying to remove commits?

Your answer is:

To be honest I am not quite sure about the difference of the two.

The difference here is the key, because Git is not really about branches, but rather about commits. If you are going to use Git at all, you must learn about commits. This will also make Git's branching model make some sense. Rather than repeat it all here, though, I'll just refer you to this answer.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文