https://www.atlassian.com/git/tutorials/git-gc

https://www.atlassian.com/git/tutorials/git-gc

The git gc command is a repository maintenance command. The "gc" stands for garbage collection. Executing git gc is literally telling Git to clean up the mess it‘s made in the current repository. Garbage collection is a concept that originates from interpreted programming languages which do dynamic memory allocation. Garbage collection in interpreted languages is used to recover memory that has become inaccessible to the executing program.

Git repositories accumulate various types of garbage. One type of Git garbage is orphaned or inaccessible commits. Git commits can become inaccessible when performing history altering commands like git resets or git rebase. In an effort to preserve history and avoid data loss Git will not delete detached commits. A detached commit can still be checked out, cherry picked, and examined through the git log.

In addition to detached commit clean up, git gc will also perform compression on stored Git Objects, freeing up precious disk space. When Git identifies a group of similar objects it will compress them into a ‘pack‘. Packs are like zip files of Git bjects and live in the ./git/objects/pack directory within a repository.

What does git gc actually do?

Before execution, git gc first checks several git config values. These values will help clarify the rest of git gc responsibility.

git gc configuration

gc.reflogExpire

An optional variable that defaults to 90 days. It is used to set how long records in a branches reflog should be preserved.

gc.reflogExpireUnreachable

An optional variable that defaults to 30 days. It is used to set how long inaccessible reflog records should be preserved.

gc.aggressiveWindow

An optional variable that defaults to 250. It controls how much time is spent in the delta compression phase of object packing when git gc is executed with the --aggressive option.

gc.aggressiveDepth

Optional variable that defaults to 50. It controls the depth of compression git-repack uses during a git gc --aggresive execution

gc.pruneExpire

Optional variable that defaults to "2 weeks ago". It sets how long a inaccessible object will be preserved before pruning

gc.worktreePruneExpire

Optional variable that defaults to "3 months ago". It sets how long a stale working tree will be preserved before being deleted.

git gc execution

Behind the scenes git gc actually executes a bundle of other internal subcommands like git prune, git repack, git pack and git rerere.

The high-level responsibility of these commands is to identify any Git objects that are outside the threshold levels set from the git gc configuration.

Once identified, these objects are then compressed, or pruned accordingly.

git gc best practices and FAQS

Garbage collection is run automatically on several frequently used commands:

The frequency in which git gc should be manually executed corresponds to the activity level of a repository.

A repository with a single contributing developer will need to execute git gc far less often than a frequently-updated multi-user repository.

git gc vs git prune

git gc is a parent command and git prune is a child.

git gc will internally trigger git prune.

git prune is used to remove Git objects that have been deemed inaccessible by the git gc configuration.

Learn more about git prune.

What is git gc aggressive?

git gc can be invoked with the --aggressive command line option.

The --aggressive option causes git gc to spend more time on its optimization effort.

This causes git gc to run slower but will save more disk space after its completion.

The effects of --aggressive are persistent and only need to be run after a large volume of changes to a repository.

What is git gc auto?

The git gc --auto command variant first checks if any housekeeping is required on the repo before executing.

If it finds housekeeping is not needed it exits without doing any work.

Some Git commands implicitly run git gc --auto after execution to clean up any loose objects they have created.

Before execution git gc --auto will check the git configuration for threshold values on loose objects and packing compression size.

These values can be set with git config.

If the repository surpasses any of the housekeeping thresholds git gc --auto will be executed.

Getting started with git gc

You‘re probably already using git gc without noticing.

As discussed in the best practices section, it is automatically invoked through frequently used commands.

If you want to manually invoke it simply execute git gc and you should see an output indicating the work it has performed.

原文地址:https://www.cnblogs.com/chucklu/p/11505623.html

时间: 2025-01-14 03:14:02

https://www.atlassian.com/git/tutorials/git-gc的相关文章

Git起步--git安装与初次运行git前配置

在你开始使用 Git 前,需要将它安装在你的计算机上. 即便已经安装,最好将它升级到最新的版本. 你可以通过软件包或者其它安装程序来安装,或者下载源码编译安装. 一.Git安装 1. 在linux上安装 我们可以使用发行版包含的基础软件包管理工具来安装,如果基于Fedora,我们可以使用  $ sudo yum install git 如果基于Debian,我们可以尝试apt-get  $ sudo apt-get install git Git 官方网站上有在各种 Unix 风格的系统上安装步

Android Studio配置Git及Git文件状态说明

Android Studio配置Git还是比较简单的,麻烦的是可能中间出现各种问题.如果你想了解或感兴趣,请往下看. 首先你得下载Git客户端,网址:http://git-scm.com/download/. 根据需要下载相应的版本,并安装.然后在Android Studio中指定git.exe,点击“Test”,成功则会弹出以下提示. 由于我用的是Android Studio 2.0 Preview,根本不存在“Enable Version Control Integration”提示,害我找

【Git】Git远程操作详解

Git是目前最流行的版本管理系统,学会Git几乎成了开发者的必备技能. Git有很多优势,其中之一就是远程操作非常简便.本文详细介绍5个Git命令,它们的概念和用法,理解了这些内容,你就会完全掌握Git远程操作. git clone git remote git fetch git pull git push 本文针对初级用户,从最简单的讲起,但是需要读者对Git的基本用法有所了解.同时,本文覆盖了上面5个命令的几乎所有的常用用法,所以对于熟练用户也有参考价值. 一.git clone 远程操作

使用Git、Git GUI和TortoiseGit

1. 关于命令行 我一直建议在命令行中使用Git或者SVN.因为这样可能更加了解他们的工作方式,也不容易遗漏重要的问题和提醒. 在Windows习惯的驱使下,大多数人是不会看弹出的对话框中有什么信息的,一般都是直接关掉.但是,版本库给我们的提示信息都是非常重要的,有的是冲突,有的是提交失败,等等,这些都被略过了. 我碰到的关于版本库使用问题主要包括下面这些: 没有获取到最新版本就编译程序出现这个问题的原因,主要是忽略了文件的冲突.有的是从不看版本库给的提示,有的是太依赖Windows资源管理器中

Centos6.8搭建Git服务(git版本可选)

搭建Git服务器需要准备一台运行Linux的机器,本文以Centos6.8纯净版系统为例搭建自己的Git服务. 准备工作:以root用户登陆自己的Linux服务器. 第一步安装依赖库 [[email protected] ~]# yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel [[email protected] ~]# yum install gcc perl-ExtUtils-MakeMake

Git 入门 ---- Git 常用命令

本文作为  Git 入门 ---- Git 与 SVN 区别 的续篇,继续介绍 Git 的入门知识 四. Git 安装 OS X 版本: Mac 一般自带不需要安装 Windos 版本: https://git-for-windows.github.io/ Linux 版本: Linux 一般也是自带无需安装 五. 创建新仓库 创建新文件夹,cd 到文件夹,执行命令: git init  用来创建新 git 仓库 六. 提交文件进仓库 在新建好 git 仓库的文件夹里加入 readme.txt

[git]git的基本原理|git branch|git

继续写一篇git的文章,介绍下git的历史和基本原理. 介绍下git的历史,据砖家考究,遥想当年,linux的创始人,牛人李纳斯,开发linux用的版本控制工具BitKeeper,出于公益或友好, 是免费的,但是李纳斯手下的几个黑客试图破解BitKeeper的协议,结果被BitKeeper公司发现,就从免费转向收费. 牛人李纳斯一努之下,两周就用C撸了一个新的版本控制系统,这就是Git. 彪悍的牛人,就是这么嚣张! 下面说下它的基本原理:(以下所有内容都可以从它官网得到:https://git-

git分支切换与git rebase , git stash

今天在dev分支开发直播的其他功能,老大突然发消息说在master分支修改一下网站文章的样式,因此发生了对git的一些了解. 正在dev分支开发,那么dev分支开发的东西怎么办呢,这就要用的git的存储功能的,git stash向堆栈推送一个新的储藏,只要运行git stash这就要用的git的存储功能的 1 $ git stash 2 Saved working directory and index state WIP on dev: 3b1687c 房间加载更多 3 HEAD is now

细说git merge & git rebase

git merge和git rebase两个都是用来合并两个分支用的,在使用过程中,这两个概念容易混淆. 在此,对这两个git技巧的用法进行详细描述,希望能帮助一些热爱git的朋友. ------------------------------------------------------------------------------------------------------ git merge是用来合并两个分支的. git merge b # 将b分支合并到当前分支 同样git re