libgit2

git_checkout_strategy_t

Version:

Checkout behavior flags

In libgit2, checkout is used to update the working directory and index to match a target tree. Unlike git checkout, it does not move the HEAD commit for you - use git_repository_set_head or the like to do that.

Checkout looks at (up to) four things: the "target" tree you want to check out, the "baseline" tree of what was checked out previously, the working directory for actual files, and the index for staged changes.

You give checkout one of two strategies for update:

  • GIT_CHECKOUT_SAFE is the default, and similar to git's default, which will make modifications that will not lose changes in the working directory.

| target == baseline | target != baseline | ---------------------|-----------------------|----------------------| workdir == baseline | no action | create, update, or | | | delete file | ---------------------|-----------------------|----------------------| workdir exists and | no action | conflict (notify | is != baseline | notify dirty MODIFIED | and cancel checkout) | ---------------------|-----------------------|----------------------| workdir missing, | notify dirty DELETED | create file | baseline present | | | ---------------------|-----------------------|----------------------|

  • GIT_CHECKOUT_FORCE will take any action to make the working directory match the target (including potentially discarding modified files).

To emulate git checkout, use GIT_CHECKOUT_SAFE with a checkout notification callback (see below) that displays information about dirty files. The default behavior will cancel checkout on conflicts.

To emulate git checkout-index, use GIT_CHECKOUT_SAFE with a notification callback that cancels the operation if a dirty-but-existing file is found in the working directory. This core git command isn't quite "force" but is sensitive about some types of changes.

To emulate git checkout -f, use GIT_CHECKOUT_FORCE.

There are some additional flags to modify the behavior of checkout:

  • GIT_CHECKOUT_DRY_RUN is a dry-run strategy that checks for conflicts, etc., but doesn't make any actual changes.
  • GIT_CHECKOUT_ALLOW_CONFLICTS makes SAFE mode apply safe file updates even if there are conflicts (instead of cancelling the checkout).
  • GIT_CHECKOUT_REMOVE_UNTRACKED means remove untracked files (i.e. not in target, baseline, or index, and not ignored) from the working dir.
  • GIT_CHECKOUT_REMOVE_IGNORED means remove ignored files (that are also untracked) from the working directory as well.
  • GIT_CHECKOUT_UPDATE_ONLY means to only update the content of files that already exist. Files will not be created nor deleted. This just skips applying adds, deletes, and typechanges.
  • GIT_CHECKOUT_DONT_UPDATE_INDEX prevents checkout from writing the updated files' information to the index.
  • Normally, checkout will reload the index and git attributes from disk before any operations. GIT_CHECKOUT_NO_REFRESH prevents this reload.
  • Unmerged index entries are conflicts. GIT_CHECKOUT_SKIP_UNMERGED skips files with unmerged index entries instead. GIT_CHECKOUT_USE_OURS and GIT_CHECKOUT_USE_THEIRS to proceed with the checkout using either the stage 2 ("ours") or stage 3 ("theirs") version of files in the index.
  • GIT_CHECKOUT_DONT_OVERWRITE_IGNORED prevents ignored files from being overwritten. Normally, files that are ignored in the working directory are not considered "precious" and may be overwritten if the checkout target contains that file.
  • GIT_CHECKOUT_DONT_REMOVE_EXISTING prevents checkout from removing files or folders that fold to the same name on case insensitive filesystems. This can cause files to retain their existing names and write through existing symbolic links.

Values

GIT_CHECKOUT_SAFE
0

Allow safe updates that cannot overwrite uncommitted data. If the uncommitted changes don't conflict with the checked out files, the checkout will still proceed, leaving the changes intact.

GIT_CHECKOUT_FORCE
(1 << 1)

Allow all updates to force working directory to look like the index, potentially losing data in the process.

GIT_CHECKOUT_RECREATE_MISSING
(1 << 2)

Allow checkout to recreate missing files

GIT_CHECKOUT_ALLOW_CONFLICTS
(1 << 4)

Allow checkout to make safe updates even if conflicts are found

GIT_CHECKOUT_REMOVE_UNTRACKED
(1 << 5)

Remove untracked files not in index (that are not ignored)

GIT_CHECKOUT_REMOVE_IGNORED
(1 << 6)

Remove ignored files not in index

GIT_CHECKOUT_UPDATE_ONLY
(1 << 7)

Only update existing files, don't create new ones

GIT_CHECKOUT_DONT_UPDATE_INDEX
(1 << 8)

Normally checkout updates index entries as it goes; this stops that. Implies GIT_CHECKOUT_DONT_WRITE_INDEX.

GIT_CHECKOUT_NO_REFRESH
(1 << 9)

Don't refresh index/config/etc before doing checkout

GIT_CHECKOUT_SKIP_UNMERGED
(1 << 10)

Allow checkout to skip unmerged files

GIT_CHECKOUT_USE_OURS
(1 << 11)

For unmerged files, checkout stage 2 from index

GIT_CHECKOUT_USE_THEIRS
(1 << 12)

For unmerged files, checkout stage 3 from index

GIT_CHECKOUT_DISABLE_PATHSPEC_MATCH
(1 << 13)

Treat pathspec as simple list of exact match file paths

GIT_CHECKOUT_SKIP_LOCKED_DIRECTORIES
(1 << 18)

Ignore directories in use, they will be left empty

GIT_CHECKOUT_DONT_OVERWRITE_IGNORED
(1 << 19)

Don't overwrite ignored files that exist in the checkout target

GIT_CHECKOUT_CONFLICT_STYLE_MERGE
(1 << 20)

Write normal merge files for conflicts

GIT_CHECKOUT_CONFLICT_STYLE_DIFF3
(1 << 21)

Include common ancestor data in diff3 format files for conflicts

GIT_CHECKOUT_DONT_REMOVE_EXISTING
(1 << 22)

Don't overwrite existing files or folders

GIT_CHECKOUT_DONT_WRITE_INDEX
(1 << 23)

Normally checkout writes the index upon completion; this prevents that.

GIT_CHECKOUT_DRY_RUN
(1 << 24)

Perform a "dry run", reporting what would be done but without actually making changes in the working directory or the index.

GIT_CHECKOUT_CONFLICT_STYLE_ZDIFF3
(1 << 25)

Include common ancestor data in zdiff3 format for conflicts

GIT_CHECKOUT_NONE
(1 << 30)

Do not do a checkout and do not fire callbacks; this is primarily useful only for internal functions that will perform the checkout themselves but need to pass checkout options into another function, for example, git_clone.

GIT_CHECKOUT_UPDATE_SUBMODULES
(1 << 16)

Recursively checkout submodules with same options (NOT IMPLEMENTED)

GIT_CHECKOUT_UPDATE_SUBMODULES_IF_CHANGED
(1 << 17)

Recursively checkout submodules if HEAD moved in super repo (NOT IMPLEMENTED)

Versions