Home Explore Blog CI



git

1st chunk of `Documentation/git-replace.adoc`
02206c01300eb4e625429d0e77956da56c55ed7de51ba5970000000100000a2f
git-replace(1)
==============

NAME
----
git-replace - Create, list, delete refs to replace objects

SYNOPSIS
--------
[verse]
'git replace' [-f] <object> <replacement>
'git replace' [-f] --edit <object>
'git replace' [-f] --graft <commit> [<parent>...]
'git replace' [-f] --convert-graft-file
'git replace' -d <object>...
'git replace' [--format=<format>] [-l [<pattern>]]

DESCRIPTION
-----------
Adds a 'replace' reference in `refs/replace/` namespace.

The name of the 'replace' reference is the SHA-1 of the object that is
replaced. The content of the 'replace' reference is the SHA-1 of the
replacement object.

The replaced object and the replacement object must be of the same type.
This restriction can be bypassed using `-f`.

Unless `-f` is given, the 'replace' reference must not yet exist.

There is no other restriction on the replaced and replacement objects.
Merge commits can be replaced by non-merge commits and vice versa.

Replacement references will be used by default by all Git commands
except those doing reachability traversal (prune, pack transfer and
fsck).

It is possible to disable the use of replacement references for any
command using the `--no-replace-objects` option just after 'git'.

For example if commit 'foo' has been replaced by commit 'bar':

------------------------------------------------
$ git --no-replace-objects cat-file commit foo
------------------------------------------------

shows information about commit 'foo', while:

------------------------------------------------
$ git cat-file commit foo
------------------------------------------------

shows information about commit 'bar'.

The `GIT_NO_REPLACE_OBJECTS` environment variable can be set to
achieve the same effect as the `--no-replace-objects` option.

OPTIONS
-------
-f::
--force::
	If an existing replace ref for the same object exists, it will
	be overwritten (instead of failing).

-d::
--delete::
	Delete existing replace refs for the given objects.

--edit <object>::
	Edit an object's content interactively. The existing content
	for <object> is pretty-printed into a temporary file, an
	editor is launched on the file, and the result is parsed to
	create a new object of the same type as <object>. A
	replacement ref is then created to replace <object> with the
	newly created object. See linkgit:git-var[1] for details about
	how the editor will be chosen.

--raw::
	When editing, provide the raw object contents rather than
	pretty-printed ones. Currently this only affects trees, which
	will be shown in their binary form. This is harder to work with,
	but can help when repairing

Title: Git Replace Command
Summary
The git-replace command is used to create, list, and delete references to replace objects in a Git repository, allowing for the substitution of one object with another in Git commands. This enables replacement of commits, trees, and other objects, with options to force overwrite, edit object content, and delete existing replace refs, providing flexibility in managing Git repository history.