什么是 Git 修剪?

What is Git pruning?

我不小心修剪了一些远程分支,我真的不知道这样做的后果是什么(我点击了 Git 扩展中的 "Prune remote branches" 按钮,以为它会删除一个远程分支机构)。

官方文档说"git-prune - Prune all unreachable objects from the object database "。我真的不明白这是什么意思。我猜这可能已经删除了合并的分支,但我不太确定。

这只是垃圾收集你的分支。

这意味着,如果无法在您的任何分支的祖先中访问对象(提交),它将被删除 git 数据库,因此无法再访问。

这只是稍微清理了 git 存储库并使其更轻便。

Git Extensions 中的“Prune remote branches”执行 git remote prune 命令,删除本地远程跟踪分支,其中远程分支不再存在。

看这里:https://git-scm.com/docs/git-remote#Documentation/git-remote.txt-empruneem

Deletes stale references associated with <name>. By default, stale remote-tracking branches under <name> are deleted, but depending on global configuration and the configuration of the remote we might even prune local tags that haven’t been pushed there. Equivalent to git fetch --prune <name>, except that no new references will be fetched.

See the PRUNING section of git-fetch for what it’ll prune depending on various configuration.

With --dry-run option, report what branches would be pruned, but do not actually prune them.

可能存在远程功能分支,在我们将它们合并到 master 后删除。我们可能已经删除了功能分支作为清理的一种方式。但是如果你已经将删除的分支签出到本地系统并将状态设置为跟踪,git pull 将不会删除那些本地分支(因为它们已经与服务器断开连接)。要清理那种本地孤立分支,git prune 命令会派上用场。

了解 prune 是 repo-bound 很重要。不是每个人都知道您可以 link 您的本地存储库到多个远程。例如,当您使用开源项目并被迫通过分叉工作时,它会派上用场。

因此,prune 命令需要一个存储库名称。在大多数情况下它是 git remote prune origin,但你可以给你的 repo 起任何名字,它不一定是 origin.