LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

git-replace

Create, list, or delete object replacement refs

TLDR

Replace an object with another object
$ git replace [object] [replacement]
copy
Force replace an object, overwriting an existing replacement
$ git replace -f [object] [replacement]
copy
List all replacement refs
$ git replace --list
copy
List replacement refs matching a pattern
$ git replace --list 'refs/replace/abc*'
copy
Delete a replacement ref
$ git replace -d [object]
copy
Edit an object interactively and create a replacement
$ git replace --edit [object]
copy
Graft a commit to have different parents
$ git replace --graft [commit] [parent1] [parent2]
copy
Convert legacy grafts file to replacement refs
$ git replace --convert-graft-file
copy

SYNOPSIS

git replace [-f] object replacementgit replace [-f] --edit objectgit replace [-f] --graft commit [parent...]git replace [-f] --convert-graft-filegit replace -d object...git replace [--format=format] -l [pattern]

DESCRIPTION

git replace creates, lists, or deletes refs in the `refs/replace/` namespace that substitute one object for another. This allows changing how objects are viewed without modifying the original objects themselves.Replacements are used by default in all Git commands except reachability traversal (prune, pack transfer, fsck). To bypass replacements, use `git --no-replace-objects` or set the `GITNOREPLACE_OBJECTS` environment variable.Common use cases include fixing published history, grafting histories together, or replacing large blobs. The `--graft` option simplifies rewriting commit parentage, replacing the legacy `$GIT_DIR/info/grafts` mechanism.

PARAMETERS

-l [pattern], --list [pattern]

List replacement refs. If a pattern is given via glob(7), only matching replacements are listed.
-d, --delete
Delete existing replacement refs for the given objects.
-f, --force
Overwrite an existing replace ref for the same object instead of failing.
--graft commit [parent...]
Create a graft commit. A new commit is created with the same content as the given commit but with the specified parents, then a replacement ref is created to replace the original commit.
--convert-graft-file
Convert all entries in `$GIT_DIR/info/grafts` to replace refs and delete the grafts file. This is a one-time migration from the legacy grafts mechanism.
--edit object
Edit an object's content interactively. The existing content is pretty-printed into a temporary file, an editor is launched, and the result is used to create a replacement object.
--raw
When used with `--edit`, provide the raw object contents rather than pretty-printed ones. Useful for editing corrupted objects.
--format=format
Format for `--list` output: `short` (replaced SHA only), `medium` (replaced -> replacement), or `long` (includes object types). Default: `short`.

SEE ALSO

Copied to clipboard
Kai