git 远程修剪 –没有显示出我预期的那么多修剪过的树枝

发布于 2024-09-29 06:47:20 字数 369 浏览 4 评论 0原文

从手册页:

删除  下的所有过时跟踪分支。
这些过时的分支已从远程存储库中删除
由  引用,但仍可在“remotes/”中本地使用。

所以我使用删除了一堆分支

git push origin :staleStuff

,然后运行

git remote prune origin

但是,只修剪了一个本地分支。其中一些分支是我创建的,一些是同事创建的。这是否表明我一开始就没有正确跟踪这些分支?

From the man page:

Deletes all stale tracking branches under <name>.
These stale branches have already been removed from the remote repository
referenced by <name>, but are still locally available in "remotes/<name>".

So I removed a bunch of branches using

git push origin :staleStuff

and then ran

git remote prune origin

However, only one single local branch was pruned. Some of these branches were created by me, some by co-workers. Does this indicate that I wasn't tracking those branches correctly in the first place?

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

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

发布评论

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

评论(1

云淡风轻 2024-10-06 06:47:20

当您使用 git push origin :staleStuff 时,它会自动删除 origin/staleStuff ,因此当您运行 git remote prune origin 时,您已经修剪了一些被别人删除的分支。您的同事现在更有可能需要运行 git prune 来删除您已删除的分支。


那么 git Remote prune 到底是做什么的呢?主要思想:本地分支(不是跟踪分支)不会被 git remote prune 命令触及,应该手动删除。

现在,通过一个现实世界的示例来更好地理解:

您有一个包含 2 个分支的远程存储库:masterfeature。假设您正在两个分支上工作,因此您的本地存储库中有这些引用(给出了完整的引用名称以避免任何混淆):

  • refs/heads/master(简称<代码>master)
  • refs/heads/feature(简称feature
  • refs/remotes/origin/master(简称< code>origin/master)
  • refs/remotes/origin/feature (简称 origin/feature

现在,一个典型的场景:

  1. 其他一些开发人员完成了所有工作在 feature 上,将其合并到 master 并从远程存储库中删除 feature 分支。
  2. 默认情况下,当您执行 git fetch 或 git pull 时,不会从本地存储库中删除任何引用,因此您仍然拥有所有这 4 个引用。
  3. 您决定清理它们,并运行 git remote prune origin 。
  4. git 检测到 feature 分支不再存在,因此 refs/remotes/origin/feature 是一个陈旧分支,应该将其删除。
  5. 现在您有 3 个引用,包括 refs/heads/feature ,因为 git Remote prune 不会删除任何 refs/heads/* 引用。

可以通过branch..merge配置参数来识别与远程跟踪分支关联的本地分支。这个参数对于任何东西的工作来说并不是真正需要的(可能除了 git pull ),所以它可能会丢失。

(使用评论中的示例和有用信息进行更新)

When you use git push origin :staleStuff, it automatically removes origin/staleStuff, so when you ran git remote prune origin, you have pruned some branch that was removed by someone else. It's more likely that your co-workers now need to run git prune to get rid of branches you have removed.


So what exactly git remote prune does? Main idea: local branches (not tracking branches) are not touched by git remote prune command and should be removed manually.

Now, a real-world example for better understanding:

You have a remote repository with 2 branches: master and feature. Let's assume that you are working on both branches, so as a result you have these references in your local repository (full reference names are given to avoid any confusion):

  • refs/heads/master (short name master)
  • refs/heads/feature (short name feature)
  • refs/remotes/origin/master (short name origin/master)
  • refs/remotes/origin/feature (short name origin/feature)

Now, a typical scenario:

  1. Some other developer finishes all work on the feature, merges it into master and removes feature branch from remote repository.
  2. By default, when you do git fetch (or git pull), no references are removed from your local repository, so you still have all those 4 references.
  3. You decide to clean them up, and run git remote prune origin.
  4. git detects that feature branch no longer exists, so refs/remotes/origin/feature is a stale branch which should be removed.
  5. Now you have 3 references, including refs/heads/feature, because git remote prune does not remove any refs/heads/* references.

It is possible to identify local branches, associated with remote tracking branches, by branch.<branch_name>.merge configuration parameter. This parameter is not really required for anything to work (probably except git pull), so it might be missing.

(updated with example & useful info from comments)

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