ディレクトリ 検索
Guides gitattributes giteveryday gitglossary gitignore gitmodules gitrevisions gittutorial gitworkflows Administration git archive git bundle git clean git filter-branch git fsck git gc git instaweb git reflog Basic Snapshotting git add git commit git diff git mv git reset git rm git status Branching and Merging git branch git checkout git log git merge git mergetool git stash git tag Debugging git bisect git blame git grep Email git am git format-patch git request-pull git send-email External Systems git fast-import git svn Getting and Creating Projects git clone git init Git git annotate git archimport git bisect-lk2009 git check-attr git check-mailmap git check-ref-format git checkout-index git cherry git citool git column git credential git credential-cache git credential-store git cvsexportcommit git cvsimport git cvsserver git diff-files git diff-tree git difftool git fast-export git fetch-pack git fmt-merge-msg git get-tar-commit-id git gui git http-backend git http-fetch git http-push git imap-send git index-pack git interpret-trailers git ls-remote git ls-tree git mailinfo git mailsplit git merge-file git merge-index git merge-one-file git merge-tree git mktag git mktree git name-rev git notes git p4 git pack-objects git pack-redundant git pack-refs git parse-remote git patch-id git prune git prune-packed git quiltimport git receive-pack git remote-ext git remote-fd git remote-testgit git repack git replace git rerere git send-pack git sh-i18n git sh-setup git shell git show-branch git show-index git stripspace git unpack-file git unpack-objects git upload-archive git upload-pack git var git verify-commit git verify-tag git whatchanged git worktree Inspection and Comparison git describe git shortlog git show Miscellaneous api credentials api index gitcli gitcore tutorial gitcredentials gitcvs migration gitdiffcore githooks gitk gitnamespaces gitremote helpers gitrepository layout gitsubmodules gittutorial 2 gitweb gitweb.conf pack format User Manual Patching git apply git cherry-pick git rebase git revert Plumbing Commands git cat-file git check-ignore git commit-tree git count-objects git diff-index git for-each-ref git hash-object git ls-files git merge-base git read-tree git rev-list git rev-parse git show-ref git symbolic-ref git update-index git update-ref git verify-pack git write-tree Server Admin git daemon git update-server-info Setup and Config git git config git help Sharing and Updating Projects git fetch git pull git push git remote git submodule
テキスト

命名

git-gc  - 清理不必要的文件并优化本地存储库

概要

git gc [--aggressive] [--auto] [--quiet] [--prune=<date> | --no-prune] [--force]

描述

在当前存储库中运行许多内务处理任务,例如压缩文件修订(以减少磁盘空间并提高性能)并移除可能由之前git add调用创建的不可达对象。

鼓励用户在每个存储库中定期运行此任务,以保持良好的磁盘空间利用率和良好的操作性能。

一些git命令可能会自动运行git gc; --auto详细信息请参阅下面的标志。如果您知道自己在做什么,并且所有您想要的都是永久禁用此行为而无需进一步考虑,请执行以下操作:

$ git config --global gc.auto 0

选项

--aggressive

通常git gc运行速度很快,同时提供良好的磁盘空间利用率和性能 此选项将导致git gc更积极地优化存储库,但花费更多时间。这种优化的效果是持久的,所以这个选项只需要偶尔使用; 每隔几百个变更集左右。

--auto

使用此选项,git gc检查是否需要进行任何清洁工作; 如果没有,它会退出而不执行任何工作。一些git命令git gc --auto在执行可能会产生许多松散对象的操作之后运行。

如果存储库中的松散对象太多或包装太多,则需要进行内务处理。如果松散对象的数量超过了gc.auto配置变量的值,则所有松散对象都将使用组合到一个包中git repack -d -l。将值设置gc.auto为0将禁用自动填充松散物体。

如果包装数量超过了价值gc.autoPackLimit,那么现有包装(标有.keep文件的包装除外)将通过使用-A选项合并到一个包装中git repack。设置gc.autoPackLimit为0将禁用自动合并包装。

--prune=<date>

修剪比日期更旧的松散对象(默认为2周前,可由配置变量覆盖gc.pruneExpire)。--prune =不管年龄大小,都修剪松散的物体,并且如果另一个进程同时写入存储库,则会增加腐败风险; 请参阅下面的“注意事项”。--prune默认打开。

--no-prune

不要修剪任何松动的物体。

--quiet

取消所有进度报告。

--force

git gc即使可能有另一个git gc实例在此存储库上运行,也强制运行。

组态

可选配置变量gc.reflogExpire可以设置为指示每个分支的reflog中的历史条目应该在此存储库中保持可用的时间。该设置表示为一段时间,例如90 days3 months。它默认为90 days

可选配置变量gc.reflogExpireUnreachable可设置为指示不属于当前分支的历史请求日志条目在此存储库中保持可用的时间。这些类型的条目通常是由于使用git commit --amendgit rebase而创建的,并且是在修改或重新发生之前的提交。由于这些更改不是当前项目的一部分,因此大多数用户都希望尽快过期。该选项默认为30 days

上述两个配置变量可以赋予一个模式。例如,这会将非默认到期值设置为远程跟踪分支:

[gc "refs/remotes/*"]
        reflogExpire = never
        reflogExpireUnreachable = 3 days

可选的配置变量gc.rerereResolved指示您先前解决的冲突合并记录的保存期限。这默认为60天。

可选的配置变量gc.rerereUnresolved表示保留了多久没有解决的冲突合并记录。这默认为15天。

可选的配置变量gc.packRefs确定是否git gc运行git pack-refs。可以将其设置为“notbare”,以便在所有非裸回购库中启用它,或者可以将其设置为布尔值。这默认为true。

可选配置变量gc.aggressiveWindow控制在指定--aggressive选项时优化存储库中对象的增量压缩所花费的时间。值越大,优化增量压缩花费的时间就越多。有关更多详细信息,请参阅git-repack [1]中--window'选项的文档。这默认为250。

同样,可选的配置变量gc.aggressiveDepth控制git-repack [1]中的--depth选项。默认值为50。

可选的配置变量gc.pruneExpire控制未修剪的松散对象在修剪之前必须经过多久。默认值是“2周前”。

注意

git gc尽量不要删除在存储库中任何位置引用的对象。特别是,它不仅会保存当前一组分支和标记所引用的对象,还会保留由索引引用的对象,远程跟踪分支,git filter-branchrefs / original /中保存的引用或reflogs(可引用分支中的提交后来修改或倒带)。如果您希望某些对象被删除而不是,请检查所有这些位置,并决定在您的情况下删除这些引用是否有意义。

另一方面,当git gc与另一个进程同时运行时,可能会删除另一个进程正在使用但尚未创建引用的对象。这可能会导致其他进程失败或者可能会损坏存储库,如果其他进程稍后添加对已删除对象的引用。Git有两个功能可以显着缓解这个问题:

  1. --prune保留修改时间比日期更新的任何对象以及可从其访问的所有对象。

  1. 将对象添加到数据库的大多数操作都会更新对象的修改时间(如果该对象已存在,以便应用#1)。

然而,这些功能并不能提供完整的解决方案,因此,同时运行命令的用户必须忍受一些腐败风险(实践中似乎很低),除非他们关闭自动垃圾收集git config gc.auto 0

Hooks

git gc --auto命令将运行该pre-auto-gc钩子。有关更多信息,请参阅githooks [5]。

前の記事: 次の記事: