10

我在 BitBucket 上创建了一个 git repo 的分支(我们称之为fork_origin)。现在上游存储库(我们称之为upstream_origin)已经有许多分支合并到它的主库中并被删除。所以跑步

git fetch --prune upstream_origin

删除了很多remote/upstream_origin/分支,但现在这些相同的分支仍然存在于remote/fork_origin/命名空间中。

是否有标准的 git 命令来处理这个问题?我想远离在远程存储库上进行大规模删除的复杂 bash 脚本。

更新:

正如建议的那样,我尝试使用远程修剪命令:

git remote prune fork_origin

但是,它没有任何效果。经过进一步调查,这似乎只适用于“陈旧”的分支,但是当我运行时:

git remote show fork_origin

它表明所有分支仍然被“跟踪”。git remote prune因此,该命令没有什么陈旧的东西可以删除是有道理的。有没有办法强制远程 repo ( fork_origin) 更新其相对于的分支状态upstream_origin

4

3 回答 3

3

如果要删除远程上的分支,请使用以下命令:

git remote prune fork_origin

但在此之前,看看这个线程,看看会出现什么问题:git remote prune - 没有像我预期的那样显示修剪过的分支

于 2013-05-04T12:27:45.480 回答
0

没有一个 git 命令,但你需要;

  • 拿来fork_origin
  • 识别任何remotes/fork_origin/branch不再存在的remotes/upstream_origin(因为你的git fetch --prune upstream_origin
  • git push --delete thoseBranches

这有点类似于“在 git 中删除多个远程分支”。

于 2014-01-12T09:04:21.003 回答
0

对于 Linux 和 Mac 用户,此命令将删除我工作中已在上游删除的所有分支。

git branch -a | grep origin | awk -F \/ '{print $NF}' > _my_branches.txt; git branch -a | grep upstream | awk -F \/ '{print $NF}' > _upstream_branches.txt; for deleted_branch_name in `comm -23 _my_branches.txt _upstream_branches.txt`; do git push origin :$deleted_branch_name; done

如果您更喜欢有步骤而不是一个长命令:

# Find the branches in my fork
git branch -a | grep origin | awk -F \/ '{print $NF}' > _my_branches.txt; 
# Find the branches still in upstream
git branch -a | grep upstream | awk -F \/ '{print $NF}' > _upstream_branches.txt;
# See only the ones that are still in my fork with the comm command
# And only for those branches issue a git command to prunbe them from my fork.
for deleted_branch_name in `comm -23 _my_branches.txt _upstream_branches.txt`; do git push origin :$deleted_branch_name; done
于 2017-04-06T10:16:28.853 回答