不再在远程删除本地分支

编程入门 行业动态 更新时间:2024-10-23 05:32:58
本文介绍了不再在远程删除本地分支的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

是否有一种简单的方法可以删除所有没有远程等价物的本地分行?

例子:

分支机构(本地和远程)

  • master
  • origin / master
  • origin / bug-fix-a
  • origin / bug-fix-b
  • origin / bug-fix-c

在本地,我只有一个主分支。现在我需要处理一个bug修复一个,所以我检查一下,处理它,然后将更改推送到远程。接下来,我也对 bug-fix-b 执行相同操作。

分支(本地和远程)

  • master
  • bug-fix-a
  • bug-fix-b
  • origin / master
  • origin / bug-fix-a
  • origin / bug-fix-b
  • origin / bug-fix -c

现在我有本地分支 master , bug-fix-a , bug-fix-b 。 Master分支的维护者会将我的更改合并到master中,并删除他已经合并的所有分支。

所以当前状态为: p>

分支机构(本地和远程)

  • master
  • bug-fix-a
  • bug-fix-b
  • origin / master
  • / bug-fix -c

现在我想调用一些命令来删除分支(在这种情况下为 bug-fix -a , bug-fix-b ),它们不再在远程仓库中表示。

像现有命令 git remote prune origin ,但更像是 git local prune origin 。

解决方案

git remote prune origin b

git branch --merged 列出已合并到当前分支的分支。

xargs git branch -d 删除标准输入中列出的分支。

小心删除由所列的分支

为了让您有机会在删除分支之前编辑列表,你可以在一行中做以下操作:

git branch --merged> / tmp / merged-branches &安培;&安培; vi / tmp / merged-branches&& xargs git branch -d< / tmp / merged-branches

Is there a simple way to delete all local branches which do not have a remote equivalent?

Example:

Branches (local and remote)

  • master
  • origin/master
  • origin/bug-fix-a
  • origin/bug-fix-b
  • origin/bug-fix-c

Locally, I only have a master branch. Now I need to work on bug-fix-a, so I check it out, work on it, and push changes to the remote. Next I do the same with bug-fix-b.

Branches (local and remote)

  • master
  • bug-fix-a
  • bug-fix-b
  • origin/master
  • origin/bug-fix-a
  • origin/bug-fix-b
  • origin/bug-fix-c

Now I have local branches master, bug-fix-a, bug-fix-b. The Master branch maintainer will merge my changes into master and delete all branches he has already merged.

So the current state is now:

Branches (local and remote)

  • master
  • bug-fix-a
  • bug-fix-b
  • origin/master
  • origin/bug-fix-c

Now I would like to call some command to delete branches (in this case bug-fix-a, bug-fix-b), which are no longer represented in the remote repository.

It would be something like the existing command git remote prune origin, but more like git local prune origin.

解决方案

git remote prune origin prunes tracking branches not on the remote.

git branch --merged lists branches that have been merged into the current branch.

xargs git branch -d deletes branches listed on standard input.

Be careful deleting branches listed by git branch --merged. The list could include master or other branches you'd prefer not to delete.

To give yourself the opportunity to edit the list before deleting branches, you could do the following in one line:

git branch --merged >/tmp/merged-branches && vi /tmp/merged-branches && xargs git branch -d </tmp/merged-branches

更多推荐

不再在远程删除本地分支

本文发布于:2023-11-14 13:43:31,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:分支

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!