什么是 Git 修剪?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/36082788/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is Git pruning?
提问by Daniel Ball
I've accidentally pruned some remote branches and I don't really know what the consequence of this is (I clicked the "Prune remote branches" button in Git Extensions, thinking it would delete a remote branch).
我不小心修剪了一些远程分支,我真的不知道这样做的后果是什么(我在 Git 扩展中单击了“修剪远程分支”按钮,认为它会删除远程分支)。
The official documentation says "git-prune - Prune all unreachable objects from the object database ". I don't really understand what this means. I'm guessing this might have removed merged branches but I'm not really sure.
官方文档说“git-prune - 从对象数据库中修剪所有无法访问的对象”。我真的不明白这是什么意思。我猜这可能已经删除了合并的分支,但我不确定。
回答by 1615903
"Prune remote branches" in Git Extensions executes git remote prune
command, which removes your local remote tracking branches where the branch no longer exists on the remote.
Git Extensions 中的“修剪远程分支”执行git remote prune
命令,该命令将删除您的本地远程跟踪分支,其中远程不再存在该分支。
See here: https://git-scm.com/docs/git-remote#git-remote-empruneem
请参阅此处:https: //git-scm.com/docs/git-remote#git-remote-empruneem
回答by blue112
This just garbage collects your branches.
这只是垃圾收集你的分支。
Thats means, if an object (a commit) cannot be reached in any of your branch's ancestors, it will be removed for the git database, and as such couldn't be reach anymore.
这意味着,如果在您的任何分支的祖先中无法访问对象(提交),它将被 git 数据库删除,因此无法再访问。
This just cleans up a little the git repository and make it lighter.
这只是清理了一点 git 存储库并使其更轻。
回答by yuranos
It's important to know that prune is repo-bound. Not everyone knows that you can link your local repo to multiple remotes. It comes in handy when, for example, you work with an open-source project and is enforced to work via forks.
重要的是要知道prune 是 repo-bound。不是每个人都知道您可以将本地存储库链接到多个遥控器。例如,当您使用开源项目并强制通过 fork 工作时,它会派上用场。
So, prune command requires a repo name. In most cases it's git remote prune origin
, but you can call your repo anything, it doesn't have to be origin
.
因此,prune 命令需要一个 repo 名称。在大多数情况下它是git remote prune origin
,但你可以调用你的 repo 任何东西,它不一定是origin
。
回答by Santhosh J
There may be remote feature branches which are removed after we merge them into master. We might have deleted the feature branches as a way of cleaning up. But if you had checked out the deleted branch to the local system and set to status as tracking, git pull will not delete those local branches (because those are already disconnected from the server). To clean up that kind of local orphan branches, git prune
command will come handy to help.
在我们将它们合并到 master 之后,可能会删除远程功能分支。我们可能已经删除了功能分支作为清理的一种方式。但是,如果您已将已删除的分支检出到本地系统并将状态设置为跟踪,则 git pull 将不会删除这些本地分支(因为它们已经与服务器断开连接)。要清理那种本地孤儿分支,git prune
命令将派上用场。