interplane.Get Omega
Read in your language

git

[Ported from github.com/git/git] Sync with Git 2.56.1

Brought by drakestapleton

branch master Branches Tags History

git / Documentation / git-maintenance.adoc

449 lines · 20377 bytes Raw Blame History
1git-maintenance(1)
2==================
3
4NAME
5----
6git-maintenance - Run tasks to optimize Git repository data
7
8
9SYNOPSIS
10--------
11[verse]
12'git maintenance' run [<options>]
13'git maintenance' start [--scheduler=<scheduler>]
14'git maintenance' (stop|register|unregister) [<options>]
15'git maintenance' is-needed [<options>]
16
17
18DESCRIPTION
19-----------
20Run tasks to optimize Git repository data, speeding up other Git commands
21and reducing storage requirements for the repository.
22
23Git commands that add repository data, such as `git add` or `git fetch`,
24are optimized for a responsive user experience. These commands do not take
25time to optimize the Git data, since such optimizations scale with the full
26size of the repository while these user commands each perform a relatively
27small action.
28
29The `git maintenance` command provides flexibility for how to optimize the
30Git repository.
31
32SUBCOMMANDS
33-----------
34
35run::
36 Run one or more maintenance tasks. If one or more `--task` options
37 are specified, then those tasks are run in that order. Otherwise,
38 the tasks are determined by which `maintenance.<task>.enabled`
39 config options are true. By default, only `maintenance.gc.enabled`
40 is true.
41
42start::
43 Start running maintenance on the current repository. This performs
44 the same config updates as the `register` subcommand, then updates
45 the background scheduler to run `git maintenance run --scheduled`
46 on an hourly basis.
47
48stop::
49 Halt the background maintenance schedule. The current repository
50 is not removed from the list of maintained repositories, in case
51 the background maintenance is restarted later.
52
53register::
54 Initialize Git config values so any scheduled maintenance will start
55 running on this repository. This adds the repository to the
56 `maintenance.repo` config variable in the current user's global config,
57 or the config specified by --config-file option, and enables some
58 recommended configuration values for `maintenance.<task>.schedule`. The
59 tasks that are enabled are safe for running in the background without
60 disrupting foreground processes.
61+
62The `register` subcommand will also set the `maintenance.strategy` config
63value to `incremental`, if this value is not previously set. The
64`incremental` strategy uses the following schedule for each maintenance
65task:
66+
67--
68* `gc`: disabled.
69* `commit-graph`: hourly.
70* `prefetch`: hourly.
71* `loose-objects`: daily.
72* `incremental-repack`: daily.
73--
74+
75`git maintenance register` will also disable foreground maintenance by
76setting `maintenance.auto = false` in the current repository. This config
77setting will remain after a `git maintenance unregister` command.
78
79unregister::
80 Remove the current repository from background maintenance. This
81 only removes the repository from the configured list. It does not
82 stop the background maintenance processes from running.
83+
84The `unregister` subcommand will report an error if the current repository
85is not already registered. Use the `--force` option to return success even
86when the current repository is not registered.
87
88is-needed::
89 Check whether maintenance needs to be run without actually running it.
90 Exits with a 0 status code if maintenance needs to be run, 1 otherwise.
91 Ideally used with the '--auto' flag.
92+
93If one or more `--task` options are specified, then those tasks are checked
94in that order. Otherwise, the tasks are determined by which
95`maintenance.<task>.enabled` config options are true. By default, only
96`maintenance.gc.enabled` is true.
97
98[[TASKS]]
99TASKS
100-----
101
102commit-graph::
103 The `commit-graph` job updates the `commit-graph` files incrementally,
104 then verifies that the written data is correct. The incremental
105 write is safe to run alongside concurrent Git processes since it
106 will not expire `.graph` files that were in the previous
107 `commit-graph-chain` file. They will be deleted by a later run based
108 on the expiration delay.
109
110prefetch::
111 The `prefetch` task updates the object directory with the latest
112 objects from all registered remotes. For each remote, a `git fetch`
113 command is run. The configured refspec is modified to place all
114 requested refs within `refs/prefetch/`. Also, tags are not updated.
115+
116This is done to avoid disrupting the remote-tracking branches. The end users
117expect these refs to stay unmoved unless they initiate a fetch. However,
118with the prefetch task, the objects necessary to complete a later real fetch
119would already be obtained, making the real fetch faster. In the ideal case,
120it will just become an update to a bunch of remote-tracking branches without
121any object transfer.
122+
123The `remote.<name>.skipFetchAll` configuration can be used to
124exclude a particular remote from getting prefetched.
125
126gc::
127 Clean up unnecessary files and optimize the local repository. "GC"
128 stands for "garbage collection," but this task performs many
129 smaller tasks. This task can be expensive for large repositories,
130 as it repacks all Git objects into a single pack-file. It can also
131 be disruptive in some situations, as it deletes stale data. See
132 linkgit:git-gc[1] for more details on garbage collection in Git.
133
134loose-objects::
135 The `loose-objects` job cleans up loose objects and places them into
136 pack-files. In order to prevent race conditions with concurrent Git
137 commands, it follows a two-step process. First, it deletes any loose
138 objects that already exist in a pack-file; concurrent Git processes
139 will examine the pack-file for the object data instead of the loose
140 object. Second, it creates a new pack-file (starting with "loose-")
141 containing a batch of loose objects.
142+
143The batch size defaults to fifty thousand objects to prevent the job from
144taking too long on a repository with many loose objects. Use the
145`maintenance.loose-objects.batchSize` config option to adjust this size,
146including a value of `0` to remove the limit.
147+
148The `gc` task writes unreachable objects as loose objects to be cleaned up
149by a later step only if they are not re-added to a pack-file; for this
150reason it is not advisable to enable both the `loose-objects` and `gc`
151tasks at the same time.
152
153incremental-repack::
154 The `incremental-repack` job repacks the object directory
155 using the `multi-pack-index` feature. In order to prevent race
156 conditions with concurrent Git commands, it follows a two-step
157 process. First, it calls `git multi-pack-index expire` to delete
158 pack-files unreferenced by the `multi-pack-index` file. Second, it
159 calls `git multi-pack-index repack` to select several small
160 pack-files and repack them into a bigger one, and then update the
161 `multi-pack-index` entries that refer to the small pack-files to
162 refer to the new pack-file. This prepares those small pack-files
163 for deletion upon the next run of `git multi-pack-index expire`.
164 The selection of the small pack-files is such that the expected
165 size of the big pack-file is at least the batch size; see the
166 `--batch-size` option for the `repack` subcommand in
167 linkgit:git-multi-pack-index[1]. The default batch-size is zero,
168 which is a special case that attempts to repack all pack-files
169 into a single pack-file.
170
171pack-refs::
172 The `pack-refs` task collects the loose reference files and
173 collects them into a single file. This speeds up operations that
174 need to iterate across many references. See linkgit:git-pack-refs[1]
175 for more information.
176
177reflog-expire::
178 The `reflog-expire` task deletes any entries in the reflog older than the
179 expiry threshold. See linkgit:git-reflog[1] for more information.
180
181rerere-gc::
182 The `rerere-gc` task invokes garbage collection for stale entries in
183 the rerere cache. See linkgit:git-rerere[1] for more information.
184
185worktree-prune::
186 The `worktree-prune` task deletes stale or broken worktrees. See
187 linkgit:git-worktree[1] for more information.
188
189OPTIONS
190-------
191--auto::
192 When combined with the `run` subcommand, run maintenance tasks
193 only if certain thresholds are met. For example, the `gc` task
194 runs when the number of loose objects exceeds the number stored
195 in the `gc.auto` config setting, or when the number of pack-files
196 exceeds the `gc.autoPackLimit` config setting. Not compatible with
197 the `--schedule` option.
198 When combined with the `is-needed` subcommand, check if the required
199 thresholds are met without actually running maintenance.
200
201--schedule::
202 When combined with the `run` subcommand, run maintenance tasks
203 only if certain time conditions are met, as specified by the
204 `maintenance.<task>.schedule` config value for each `<task>`.
205 This config value specifies a number of seconds since the last
206 time that task ran, according to the `maintenance.<task>.lastRun`
207 config value. The tasks that are tested are those provided by
208 the `--task=<task>` option(s) or those with
209 `maintenance.<task>.enabled` set to true.
210
211--quiet::
212 Do not report progress or other information over `stderr`.
213
214--task=<task>::
215 If this option is specified one or more times, then only run the
216 specified tasks in the specified order. If no `--task=<task>`
217 arguments are specified, then only the tasks with
218 `maintenance.<task>.enabled` configured as `true` are considered.
219 See the <<TASKS,'TASKS'>> section for the list of accepted `<task>` values.
220
221--scheduler=auto|crontab|systemd-timer|launchctl|schtasks::
222 When combined with the `start` subcommand, specify the scheduler
223 for running the hourly, daily and weekly executions of
224 `git maintenance run`.
225 Possible values for `<scheduler>` are `auto`, `crontab`
226 (POSIX), `systemd-timer` (Linux), `launchctl` (macOS), and
227 `schtasks` (Windows). When `auto` is specified, the
228 appropriate platform-specific scheduler is used; on Linux,
229 `systemd-timer` is used if available, otherwise
230 `crontab`. Default is `auto`.
231
232
233TROUBLESHOOTING
234---------------
235The `git maintenance` command is designed to simplify the repository
236maintenance patterns while minimizing user wait time during Git commands.
237A variety of configuration options are available to allow customizing this
238process. The default maintenance options focus on operations that complete
239quickly, even on large repositories.
240
241Users may find some cases where scheduled maintenance tasks do not run as
242frequently as intended. Each `git maintenance run` command takes a lock on
243the repository's object database, and this prevents other concurrent
244`git maintenance run` commands from running on the same repository. Without
245this safeguard, competing processes could leave the repository in an
246unpredictable state.
247
248The background maintenance schedule runs `git maintenance run` processes
249on an hourly basis. Each run executes the "hourly" tasks. At midnight,
250that process also executes the "daily" tasks. At midnight on the first day
251of the week, that process also executes the "weekly" tasks. A single
252process iterates over each registered repository, performing the scheduled
253tasks for that frequency. The processes are scheduled to a random minute of
254the hour per client to spread out the load that multiple clients might
255generate (e.g. from prefetching). Depending on the number of registered
256repositories and their sizes, this process may take longer than an hour.
257In this case, multiple `git maintenance run` commands may run on the same
258repository at the same time, colliding on the object database lock. This
259results in one of the two tasks not running.
260
261If you find that some maintenance windows are taking longer than one hour
262to complete, then consider reducing the complexity of your maintenance
263tasks. For example, the `gc` task is much slower than the
264`incremental-repack` task. However, this comes at a cost of a slightly
265larger object database. Consider moving more expensive tasks to be run
266less frequently.
267
268Expert users may consider scheduling their own maintenance tasks using a
269different schedule than is available through `git maintenance start` and
270Git configuration options. These users should be aware of the object
271database lock and how concurrent `git maintenance run` commands behave.
272Further, the `git gc` command should not be combined with
273`git maintenance run` commands. `git gc` modifies the object database
274but does not take the lock in the same way as `git maintenance run`. If
275possible, use `git maintenance run --task=gc` instead of `git gc`.
276
277The following sections describe the mechanisms put in place to run
278background maintenance by `git maintenance start` and how to customize
279them.
280
281BACKGROUND MAINTENANCE ON POSIX SYSTEMS
282---------------------------------------
283
284The standard mechanism for scheduling background tasks on POSIX systems
285is cron(8). This tool executes commands based on a given schedule. The
286current list of user-scheduled tasks can be found by running `crontab -l`.
287The schedule written by `git maintenance start` is similar to this:
288
289-----------------------------------------------------------------------
290# BEGIN GIT MAINTENANCE SCHEDULE
291# The following schedule was created by Git
292# Any edits made in this region might be
293# replaced in the future by a Git command.
294
2950 1-23 * * * "/<path>/git" --exec-path="/<path>" for-each-repo --config=maintenance.repo maintenance run --schedule=hourly
2960 0 * * 1-6 "/<path>/git" --exec-path="/<path>" for-each-repo --config=maintenance.repo maintenance run --schedule=daily
2970 0 * * 0 "/<path>/git" --exec-path="/<path>" for-each-repo --config=maintenance.repo maintenance run --schedule=weekly
298
299# END GIT MAINTENANCE SCHEDULE
300-----------------------------------------------------------------------
301
302The comments are used as a region to mark the schedule as written by Git.
303Any modifications within this region will be completely deleted by
304`git maintenance stop` or overwritten by `git maintenance start`.
305
306The `crontab` entry specifies the full path of the `git` executable to
307ensure that the executed `git` command is the same one with which
308`git maintenance start` was issued independent of `PATH`. If the same user
309runs `git maintenance start` with multiple Git executables, then only the
310latest executable is used.
311
312These commands use `git for-each-repo --config=maintenance.repo` to run
313`git maintenance run --schedule=<frequency>` on each repository listed in
314the multi-valued `maintenance.repo` config option. These are typically
315loaded from the user-specific global config. The `git maintenance` process
316then determines which maintenance tasks are configured to run on each
317repository with each `<frequency>` using the `maintenance.<task>.schedule`
318config options. These values are loaded from the global or repository
319config values.
320
321If the config values are insufficient to achieve your desired background
322maintenance schedule, then you can create your own schedule. If you run
323`crontab -e`, then an editor will load with your user-specific `cron`
324schedule. In that editor, you can add your own schedule lines. You could
325start by adapting the default schedule listed earlier, or you could read
326the crontab(5) documentation for advanced scheduling techniques. Please
327do use the full path and `--exec-path` techniques from the default
328schedule to ensure you are executing the correct binaries in your
329schedule.
330
331
332BACKGROUND MAINTENANCE ON LINUX SYSTEMD SYSTEMS
333-----------------------------------------------
334
335While Linux supports `cron`, depending on the distribution, `cron` may
336be an optional package not necessarily installed. On modern Linux
337distributions, systemd timers are superseding it.
338
339If user systemd timers are available, they will be used as a replacement
340of `cron`.
341
342In this case, `git maintenance start` will create user systemd timer units
343and start the timers. The current list of user-scheduled tasks can be found
344by running `systemctl --user list-timers`. The timers written by `git
345maintenance start` are similar to this:
346
347-----------------------------------------------------------------------
348$ systemctl --user list-timers
349NEXT LEFT LAST PASSED UNIT ACTIVATES
350Thu 2021-04-29 19:00:00 CEST 42min left Thu 2021-04-29 18:00:11 CEST 17min ago git-maintenance@hourly.timer git-maintenance@hourly.service
351Fri 2021-04-30 00:00:00 CEST 5h 42min left Thu 2021-04-29 00:00:11 CEST 18h ago git-maintenance@daily.timer git-maintenance@daily.service
352Mon 2021-05-03 00:00:00 CEST 3 days left Mon 2021-04-26 00:00:11 CEST 3 days ago git-maintenance@weekly.timer git-maintenance@weekly.service
353-----------------------------------------------------------------------
354
355One timer is registered for each `--schedule=<frequency>` option.
356
357The definition of the systemd units can be inspected in the following files:
358
359-----------------------------------------------------------------------
360~/.config/systemd/user/git-maintenance@.timer
361~/.config/systemd/user/git-maintenance@.service
362~/.config/systemd/user/timers.target.wants/git-maintenance@hourly.timer
363~/.config/systemd/user/timers.target.wants/git-maintenance@daily.timer
364~/.config/systemd/user/timers.target.wants/git-maintenance@weekly.timer
365-----------------------------------------------------------------------
366
367`git maintenance start` will overwrite these files and start the timer
368again with `systemctl --user`, so any customization should be done by
369creating a drop-in file, i.e. a `.conf` suffixed file in the
370`~/.config/systemd/user/git-maintenance@.service.d` directory.
371
372`git maintenance stop` will stop the user systemd timers and delete
373the above mentioned files.
374
375For more details, see `systemd.timer(5)`.
376
377
378BACKGROUND MAINTENANCE ON MACOS SYSTEMS
379---------------------------------------
380
381While macOS technically supports `cron`, using `crontab -e` requires
382elevated privileges and the executed process does not have a full user
383context. Without a full user context, Git and its credential helpers
384cannot access stored credentials, so some maintenance tasks are not
385functional.
386
387Instead, `git maintenance start` interacts with the `launchctl` tool,
388which is the recommended way to schedule timed jobs in macOS. Scheduling
389maintenance through `git maintenance (start|stop)` requires some
390`launchctl` features available only in macOS 10.11 or later.
391
392Your user-specific scheduled tasks are stored as XML-formatted `.plist`
393files in `~/Library/LaunchAgents/`. You can see the currently-registered
394tasks using the following command:
395
396-----------------------------------------------------------------------
397$ ls ~/Library/LaunchAgents/org.git-scm.git*
398org.git-scm.git.daily.plist
399org.git-scm.git.hourly.plist
400org.git-scm.git.weekly.plist
401-----------------------------------------------------------------------
402
403One task is registered for each `--schedule=<frequency>` option. To
404inspect how the XML format describes each schedule, open one of these
405`.plist` files in an editor and inspect the `<array>` element following
406the `<key>StartCalendarInterval</key>` element.
407
408`git maintenance start` will overwrite these files and register the
409tasks again with `launchctl`, so any customizations should be done by
410creating your own `.plist` files with distinct names. Similarly, the
411`git maintenance stop` command will unregister the tasks with `launchctl`
412and delete the `.plist` files.
413
414To create more advanced customizations to your background tasks, see
415launchctl.plist(5) for more information.
416
417
418BACKGROUND MAINTENANCE ON WINDOWS SYSTEMS
419-----------------------------------------
420
421Windows does not support `cron` and instead has its own system for
422scheduling background tasks. The `git maintenance start` command uses
423the `schtasks` command to submit tasks to this system. You can inspect
424all background tasks using the Task Scheduler application. The tasks
425added by Git have names of the form `Git Maintenance (<frequency>)`.
426The Task Scheduler GUI has ways to inspect these tasks, but you can also
427export the tasks to XML files and view the details there.
428
429Note that since Git is a console application, these background tasks
430create a console window visible to the current user. This can be changed
431manually by selecting the "Run whether user is logged in or not" option
432in Task Scheduler. This change requires a password input, which is why
433`git maintenance start` does not select it by default.
434
435If you want to customize the background tasks, please rename the tasks
436so future calls to `git maintenance (start|stop)` do not overwrite your
437custom tasks.
438
439CONFIGURATION
440-------------
441
442include::includes/cmd-config-section-all.adoc[]
443
444include::config/maintenance.adoc[]
445
446
447GIT
448---
449Part of the linkgit:git[1] suite