不再在远程删除本地分支 [英] Remove local branches no longer on remote

查看:155
本文介绍了不再在远程删除本地分支的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



例子:

分支机构(本地和远程)




  • 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 删除标准输入中列出的分支。



小心删除由所列的分支。该列表可能包括 master 或其他您不希望删除的分行。



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

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

这篇关于不再在远程删除本地分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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