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.atlassian.com/git/tutorials/git-gc的更多相关文章

  1. git使用,Git的skil-map,git配置http/https/socks5代理

    . 检出.克隆库: git clone git://git.openwrt.org/openwrt.git 2. git查看某个文件的修改历史 git log --pretty=oneline 文件名 ...

  2. 【git】git中使用https和ssh协议的区别以及它们的用法

    git可以使用四种主要的协议来传输资料: 本地协议(Local),HTTP 协议,SSH(Secure Shell)协议及 git 协议.其中,本地协议由于目前大都是进行远程开发和共享代码所以一般不常 ...

  3. Git:Git初体验——Git安装配置

    作为即将成为一个程序员的男人,一直在听别人说Git多好多好,之前也随便了解了一些,但是始终没有决心去学会.现在大四了,只有毕设和一门开学六七周只去过一次课的全员必修课外,也没有什么事情做,何不去做这些 ...

  4. git使用--git命令项目提交问题总结

    提交遇到Error  "remote ref does not exist"解决办法:git fetch -p MY_REMOTE    eg.    git fetch -p o ...

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

    Android Studio配置Git还是比较简单的,麻烦的是可能中间出现各种问题.如果你想了解或感兴趣,请往下看. 首先你得下载Git客户端,网址:http://git-scm.com/downlo ...

  6. 真正理解 git fetch, git pull 以及 FETCH_HEAD【转】

    转自:http://www.cnblogs.com/ToDoToTry/p/4095626.html 真正理解 git fetch, git pull 要讲清楚git fetch,git pull,必 ...

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

    在你开始使用 Git 前,需要将它安装在你的计算机上. 即便已经安装,最好将它升级到最新的版本. 你可以通过软件包或者其它安装程序来安装,或者下载源码编译安装. 一.Git安装 1. 在linux上安 ...

  8. 【Git】Git远程操作详解

    Git是目前最流行的版本管理系统,学会Git几乎成了开发者的必备技能. Git有很多优势,其中之一就是远程操作非常简便.本文详细介绍5个Git命令,它们的概念和用法,理解了这些内容,你就会完全掌握Gi ...

  9. Git学习01 --git add, git commit , git log ,git status, git reset --hard, head

    Git官方提供的快速入门教程:https://try.github.io/levels/1/challenges/1 特点:Git极其强大的分支管理:分布式版本 集中式版本控制系统,版本库是集中存放在 ...

随机推荐

  1. javascript 箭头函数的使用 初学者必看

    为了保证可读性,本文采用意译而非直译.另外,本文版权归原作者所有,翻译仅用于学习. 本文我们介绍箭头(arrow)函数的优点. 更简洁的语法我们先来按常规语法定义函数: 1 2 3 4 5 funct ...

  2. 无法写入配置文件...需要在IIS中手动创建此虚拟目录,才可以打开此项目

    无妄之灾   之前闲着没事写了一个webapi项目,今天下了班闲来无事就像拿出来改改,没想到打开的时候就提示出现错误. 没错就是这货,其实也不是第一次遇见这个问题了,但是之前一直没有找到解决方案,在网 ...

  3. 二:MySQL系列之SQL基本操作(二)

    本篇主要介绍SOL语句的基本操作,主要有分为 连接数据库,创建数据库.创建数据表.添加数据记录,基本的查询功能等操作. 一.针对数据库的操作 -- 1.连接数据库 mysql -uroot -p my ...

  4. null和空的区别

    python中None和Null的区别 首先了解python对象的概念 python中,万物皆对象,所有的操作都是针对对象的. 那什么是对象?5是一个int对象,‘oblong’是一个str对象,异常 ...

  5. JAVA HASH学习

    就HASH的目的来说,是为了解决内容摘要与快速索引的问题:而其算法也比较多样. JDK实现中,对String类的hashcode()进行了重载: public int hashCode() { int ...

  6. Castle Windsor Ioc 一个接口多个实现解决方案

    介绍 Castle Windsor 是微软的Ioc类库,本文主要介绍解决一个接口多个实现的解决方案 接口和类 以下内容不是真实的实际场景,仅仅是提供解决一个接口多个实现的思路. 业务场景类 先假设有一 ...

  7. js rsa sign使用笔记(加密,解密,签名,验签)

    你将会收获: js如何加密, 解密 js如何签名, 验签 js和Java交互如何相互解密, 验签(重点) 通过谷歌, 发现jsrsasign库使用者较多. 查看api发现这个库功能很健全. 本文使用方 ...

  8. ES6中构造函数内super关键字的使用

    super关键字用于访问和调用一个对象的父对象上的函数. super.prop和super[expr]表达式在类和对象字面量任何方法定义中都是有效的. 语法 super([arguments]); / ...

  9. Time Intersection

    Description Give two users' ordered online time series, and each section records the user's login ti ...

  10. 使用jQuery快速高效制作网页交互特效第一章JavaScript基础

    JavaScript 一.JavaScript概念: JavaScript面向对象事件驱动具有安全性的脚本语言,面向对象 JavaScript特点: 1.解释性语言,边运行边解释 2.和HTML页面实 ...