运行'git gui'时如何跳过“松散对象”弹出窗口
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1106529/
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
How to skip "Loose Object" popup when running 'git gui'
提问by Michael Donohue
When I run 'git gui' I get a popup that says
当我运行 'git gui' 时,我得到一个弹出窗口,上面写着
This repository currently has approximately 1500 loose objects.
It then suggests compressing the database. I've done this before, and it reduces the loose objects to about 250, but that doesn't suppress the popup. Compressing again doesn't change the number of loose objects.
然后它建议压缩数据库。我以前这样做过,它将松散的对象减少到大约 250 个,但这并不能抑制弹出窗口。再次压缩不会改变松散物体的数量。
Our current workflow requires significant use of 'rebase' as we are transitioning from Perforce, and Perforce is still the canonical SCM. Once Git is the canonical SCM, we will do regular merges, and the loose objects problem should be greatly mitigated.
我们当前的工作流程需要大量使用“rebase”,因为我们正在从 Perforce 过渡,而 Perforce 仍然是规范的 SCM。一旦 Git 成为规范的 SCM,我们将进行定期合并,松散对象问题应该会大大减轻。
In the mean time, I'd really like to make this 'helpful' popup go away.
同时,我真的很想让这个“有用”的弹出窗口消失。
回答by Esko Luontola
Since nobody had yet an answer, I looked into the code to see how to remove the code which shows up that dialog. I found the hint_gc
procedure which does it and the place where it is called. At the same time I noticed that late 2011 there was added a configuration option for disabling the dialog. This change (part of git-gui 0.16.0) was merged to Git's mainline on 2011-12-14.
由于还没有人给出答案,我查看了代码以了解如何删除显示该对话框的代码。我找到了hint_gc
执行它的程序以及调用它的地方。同时我注意到在 2011 年末添加了一个用于禁用对话框的配置选项。此更改(git-gui 0.16.0 的一部分)已于2011-12-14合并到 Git 的主线。
So if you use Git v1.7.9 or newer, you can disable the warning dialog with the following command:
因此,如果您使用 Git v1.7.9 或更高版本,则可以使用以下命令禁用警告对话框:
git config --global gui.gcwarning false
If you are using an older version, then you can edit /lib/git-core/git-gui
and remove the after 1000 hint_gc
line, or edit /usr/share/git-gui/lib/database.tcl
and remove the body of the hint_gc
procedure. (These file paths are on Cygwin - on other environments the files might be in a different locations. For Windows it is c:\Program Files\Git\mingw64\libexec\git-core\git-gui.tcl
)
如果您使用的是旧版本,那么您可以编辑/lib/git-core/git-gui
和删除该after 1000 hint_gc
行,或者编辑/usr/share/git-gui/lib/database.tcl
和删除过程的主体hint_gc
。(这些文件路径在 Cygwin 上 - 在其他环境中,这些文件可能位于不同的位置。对于 Windows,它是c:\Program Files\Git\mingw64\libexec\git-core\git-gui.tcl
)
回答by VonC
Update: git prune
would "solve" the issue, in that it will remove those loose objects
(git gc
calls git prune
, but only for loose objects older than two weeks, by default).
However, as the OP Michael Donohuementions in the comments:
更新:git prune
将“解决”问题,因为它将删除那些松散的对象
(git gc
调用git prune
,但默认情况下仅适用于超过两周的松散对象)。
然而,正如OP Michael Donohue在评论中提到的:
I do like the safety aspect of keeping the loose objects around for two weeks, should I want to go back and look at some old revisions, so I don't really like this solution.
I am not having any trouble with the size or performance of git, it is just 'git gui' that insists on asking me to compress the database, even when compressing the database would have no effect.
我确实喜欢将松散的物体保留两周的安全方面,如果我想回去看看一些旧的修订版,所以我真的不喜欢这个解决方案。
我对 git 的大小或性能没有任何问题,只是 'git gui' 坚持要求我压缩数据库,即使压缩数据库没有任何效果。
Original answer:
原答案:
The problem of "git gc
" not removing allloose objects has been reported before (late 2008, ""git gc
" doesn't seem to remove loose objects any more"
之前已经报告了“ git gc
”没有删除所有松散物体的问题(2008年末,“ ” git gc
“似乎不再去除松散物体”
git gc
only removes loose objects older than two weeks, if you really want to remove them now, run git prune.
But make sure no other git process can be active when you run it, or it could possibly step on something."
git gc
" will unpackobjects that have become unreachable and were currently in packs.
As a result, the amount of disk space used by a git repository can actually go updramatically after a "git gc
" operation, which could be surprising for someone who is running close to full on their filesystem, deletes a number of branches from a tracking repository, and then does a "git gc
" may get a very unpleasant surprise.
[
Example:]
Old branches are reserved via a tag such asnext-20081204
.
If you update the your local copy of thelinux-next
repository every day, you will accumulate a large number of these old branch tags.
If you then delete a whole series of them, and rungit-gc
, the operation will take quite a while, and the number of blocks and inodes used will grow significantly.They will disappear after a "
git prune
", but when I do this housekeeping operation, I've often wished for a--yes-I-know-what-I-am-doing-and-it's-unsafe-but-just-drop-the-unreachable-objects-cause-this-is-just-a-tracking-repository
option to "git gc".
git gc
只移除超过两周的松散物体,如果你现在真的想移除它们,运行 git prune。
但是请确保在运行它时没有其他 git 进程处于活动状态,否则它可能会踩到某些东西。"
git gc
" 将解包已变得无法访问且当前在包中的对象。
其结果是,磁盘空间由一个Git仓库使用量其实可以走了一个“后显着git gc
”的操作,这可能是令人惊讶的是谁运行接近全在他们的文件系统的人,删除了多家分支机构从跟踪储存库,然后执行“git gc
”可能会得到一个非常不愉快的惊喜。
[
示例:]
旧分支通过诸如next-20081204
.
如果你linux-next
每天更新你的本地仓库副本,你会积累大量这些旧的分支标签。
如果然后删除整个系列,然后运行git-gc
,则操作将花费相当长的时间,并且使用的块和 inode 的数量将显着增加。它们会在“
git prune
”后消失,但是当我进行这种内务操作时,我经常希望有一个--yes-I-know-what-I-am-doing-and-it's-unsafe-but-just-drop-the-unreachable-objects-cause-this-is-just-a-tracking-repository
“git gc”选项。
So in your case, would a "git prune
" be helpful?
所以在你的情况下,“ git prune
”会有所帮助吗?
(possibly with using "now" in the gc.pruneexpire
config variable, needed for the above behavior to happen).
(可能在gc.pruneexpire
配置变量中使用“now”,这是发生上述行为所必需的)。
You also have (from the same thread):
你也有(来自同一个线程):
repack -a -d -l
Notice the lowercase 'a'.
git-gc
calls repack with uppercase 'A' which is what causes the unreachable objects to be unpacked. Little 'a', is for people who know what they are doing, and want git to just drop unreachable objects.
注意小写的“a”。
git-gc
使用大写的“A”调用重新打包,这就是导致无法访问的对象被解包的原因。小“a”适用于知道自己在做什么并且希望 git 只删除无法访问的对象的人。
回答by Nick Dandoulakis
When "Loose Object" popup I know it's time to run git's garbage collector:
当“松散对象”弹出窗口时,我知道是时候运行 git 的垃圾收集器了:
git gc
After that the popup goes away.
Update:(due to T.E.D.'s suggestion)
I extracted the below routine from git/share/git-gui/lib/database.tcl
You can modify it to meet your needs.
之后,弹出窗口消失。
更新:(由于 TED 的建议)
我从git/share/git-gui/lib/database.tcl
您可以修改它以满足您的需要中提取了以下例程。
proc hint_gc {} {
set object_limit 8
if {[is_Windows]} {
set object_limit 1
}
set objects_current [llength [glob \
-directory [gitdir objects 42] \
-nocomplain \
-tails \
-- \
*]]
if {$objects_current >= $object_limit} {
set objects_current [expr {$objects_current * 256}]
set object_limit [expr {$object_limit * 256}]
if {[ask_popup \
[mc "This repository currently has approximately %i loose objects.
To maintain optimal performance it is strongly recommended that you compress the database when more than %i loose objects exist.
Compress the database now?" $objects_current $object_limit]] eq yes} {
do_gc
}
}
}