blob: 246dc9943c223d34c72d7b90f40ee8f523b7d77e [file] [log] [blame]
Junio C Hamanofe24db02009-08-22 05:10:471git-replace(1)
2==============
3
4NAME
5----
6git-replace - Create, list, delete refs to replace objects
7
8SYNOPSIS
9--------
10[verse]
11'git replace' [-f] <object> <replacement>
Junio C Hamanoc8c398a2014-06-16 21:14:0512'git replace' [-f] --edit <object>
Junio C Hamanod9421af2014-07-27 23:13:0013'git replace' [-f] --graft <commit> [<parent>...]
Junio C Hamanob9d9d902018-05-23 07:07:4214'git replace' [-f] --convert-graft-file
Junio C Hamanofe24db02009-08-22 05:10:4715'git replace' -d <object>...
Junio C Hamano21bc18b2014-01-10 20:33:0716'git replace' [--format=<format>] [-l [<pattern>]]
Junio C Hamanofe24db02009-08-22 05:10:4717
18DESCRIPTION
19-----------
Junio C Hamanod0316112012-08-22 19:55:2920Adds a 'replace' reference in `refs/replace/` namespace.
Junio C Hamanofe24db02009-08-22 05:10:4721
Junio C Hamanoe3f080d2013-04-22 02:27:1322The name of the 'replace' reference is the SHA-1 of the object that is
23replaced. The content of the 'replace' reference is the SHA-1 of the
Junio C Hamanofe24db02009-08-22 05:10:4724replacement object.
25
Junio C Hamano369e3402013-10-15 18:40:2526The replaced object and the replacement object must be of the same type.
27This restriction can be bypassed using `-f`.
28
Junio C Hamanod0316112012-08-22 19:55:2929Unless `-f` is given, the 'replace' reference must not yet exist.
Junio C Hamanofe24db02009-08-22 05:10:4730
Junio C Hamano369e3402013-10-15 18:40:2531There is no other restriction on the replaced and replacement objects.
32Merge commits can be replaced by non-merge commits and vice versa.
33
Junio C Hamano076ffcc2013-02-06 05:13:2134Replacement references will be used by default by all Git commands
Junio C Hamano5706e0b2009-11-24 10:54:1635except those doing reachability traversal (prune, pack transfer and
36fsck).
Junio C Hamano3d23a0a2009-10-19 08:04:3037
Junio C Hamano5706e0b2009-11-24 10:54:1638It is possible to disable use of replacement references for any
39command using the `--no-replace-objects` option just after 'git'.
Junio C Hamano3d23a0a2009-10-19 08:04:3040
Junio C Hamano5706e0b2009-11-24 10:54:1641For example if commit 'foo' has been replaced by commit 'bar':
Junio C Hamano3d23a0a2009-10-19 08:04:3042
43------------------------------------------------
Junio C Hamano5706e0b2009-11-24 10:54:1644$ git --no-replace-objects cat-file commit foo
Junio C Hamano3d23a0a2009-10-19 08:04:3045------------------------------------------------
46
Junio C Hamano5706e0b2009-11-24 10:54:1647shows information about commit 'foo', while:
Junio C Hamano3d23a0a2009-10-19 08:04:3048
49------------------------------------------------
50$ git cat-file commit foo
51------------------------------------------------
52
Junio C Hamano5706e0b2009-11-24 10:54:1653shows information about commit 'bar'.
54
Junio C Hamano042f2142016-06-27 18:05:0555The `GIT_NO_REPLACE_OBJECTS` environment variable can be set to
Junio C Hamano5706e0b2009-11-24 10:54:1656achieve the same effect as the `--no-replace-objects` option.
Junio C Hamano3d23a0a2009-10-19 08:04:3057
Junio C Hamanofe24db02009-08-22 05:10:4758OPTIONS
59-------
60-f::
Junio C Hamano369e3402013-10-15 18:40:2561--force::
Junio C Hamanofe24db02009-08-22 05:10:4762If an existing replace ref for the same object exists, it will
63be overwritten (instead of failing).
64
65-d::
Junio C Hamano369e3402013-10-15 18:40:2566--delete::
Junio C Hamanofe24db02009-08-22 05:10:4767Delete existing replace refs for the given objects.
68
Junio C Hamanoc8c398a2014-06-16 21:14:0569--edit <object>::
70Edit an object's content interactively. The existing content
71for <object> is pretty-printed into a temporary file, an
72editor is launched on the file, and the result is parsed to
73create a new object of the same type as <object>. A
74replacement ref is then created to replace <object> with the
75newly created object. See linkgit:git-var[1] for details about
76how the editor will be chosen.
77
Junio C Hamano6f0c9442014-07-16 21:51:3278--raw::
79When editing, provide the raw object contents rather than
80pretty-printed ones. Currently this only affects trees, which
81will be shown in their binary form. This is harder to work with,
82but can help when repairing a tree that is so corrupted it
83cannot be pretty-printed. Note that you may need to configure
84your editor to cleanly read and write binary data.
85
Junio C Hamanod9421af2014-07-27 23:13:0086--graft <commit> [<parent>...]::
87Create a graft commit. A new commit is created with the same
88content as <commit> except that its parents will be
89[<parent>...] instead of <commit>'s parents. A replacement ref
90is then created to replace <commit> with the newly created
Junio C Hamanob9d9d902018-05-23 07:07:4291commit. Use `--convert-graft-file` to convert a
92`$GIT_DIR/info/grafts` file and use replace refs instead.
93
94--convert-graft-file::
95Creates graft commits for all entries in `$GIT_DIR/info/grafts`
96and deletes that file upon success. The purpose is to help users
97with transitioning off of the now-deprecated graft file.
Junio C Hamanod9421af2014-07-27 23:13:0098
Junio C Hamanofe24db02009-08-22 05:10:4799-l <pattern>::
Junio C Hamano369e3402013-10-15 18:40:25100--list <pattern>::
Junio C Hamanofe24db02009-08-22 05:10:47101List replace refs for objects that match the given pattern (or
102all if no pattern is given).
103Typing "git replace" without arguments, also lists all replace
104refs.
105
Junio C Hamano21bc18b2014-01-10 20:33:07106--format=<format>::
107When listing, use the specified <format>, which can be one of
108'short', 'medium' and 'long'. When omitted, the format
109defaults to 'short'.
110
111FORMATS
112-------
113
114The following format are available:
115
116* 'short':
117<replaced sha1>
118* 'medium':
119<replaced sha1> -> <replacement sha1>
120* 'long':
121<replaced sha1> (<replaced type>) -> <replacement sha1> (<replacement type>)
122
Junio C Hamano369e3402013-10-15 18:40:25123CREATING REPLACEMENT OBJECTS
124----------------------------
125
126linkgit:git-filter-branch[1], linkgit:git-hash-object[1] and
127linkgit:git-rebase[1], among other git commands, can be used to create
Junio C Hamanoc8c398a2014-06-16 21:14:05128replacement objects from existing objects. The `--edit` option can
129also be used with 'git replace' to create a replacement object by
130editing an existing object.
Junio C Hamano369e3402013-10-15 18:40:25131
132If you want to replace many blobs, trees or commits that are part of a
133string of commits, you may just want to create a replacement string of
134commits and then only replace the commit at the tip of the target
135string of commits with the commit at the tip of the replacement string
136of commits.
137
Junio C Hamanofe24db02009-08-22 05:10:47138BUGS
139----
140Comparing blobs or trees that have been replaced with those that
Junio C Hamano1aa40d22010-01-21 17:46:43141replace them will not work properly. And using `git reset --hard` to
Junio C Hamanofe24db02009-08-22 05:10:47142go back to a replaced commit will move the branch to the replacement
143commit instead of the replaced commit.
144
145There may be other problems when using 'git rev-list' related to
Junio C Hamano369e3402013-10-15 18:40:25146pending objects.
Junio C Hamanofe24db02009-08-22 05:10:47147
148SEE ALSO
149--------
Junio C Hamano369e3402013-10-15 18:40:25150linkgit:git-hash-object[1]
151linkgit:git-filter-branch[1]
152linkgit:git-rebase[1]
Junio C Hamanofe24db02009-08-22 05:10:47153linkgit:git-tag[1]
154linkgit:git-branch[1]
Junio C Hamanoc8c398a2014-06-16 21:14:05155linkgit:git-commit[1]
156linkgit:git-var[1]
Junio C Hamano3d23a0a2009-10-19 08:04:30157linkgit:git[1]
Junio C Hamanofe24db02009-08-22 05:10:47158
Junio C Hamanofe24db02009-08-22 05:10:47159GIT
160---
161Part of the linkgit:git[1] suite