Documentation/replace: add Creating Replacement Objects section
[git] / Documentation / git-replace.txt
1 git-replace(1)
2 ==============
3
4 NAME
5 ----
6 git-replace - Create, list, delete refs to replace objects
7
8 SYNOPSIS
9 --------
10 [verse]
11 'git replace' [-f] <object> <replacement>
12 'git replace' -d <object>...
13 'git replace' -l [<pattern>]
14
15 DESCRIPTION
16 -----------
17 Adds a 'replace' reference in `refs/replace/` namespace.
18
19 The name of the 'replace' reference is the SHA-1 of the object that is
20 replaced. The content of the 'replace' reference is the SHA-1 of the
21 replacement object.
22
23 The replaced object and the replacement object must be of the same type.
24 This restriction can be bypassed using `-f`.
25
26 Unless `-f` is given, the 'replace' reference must not yet exist.
27
28 There is no other restriction on the replaced and replacement objects.
29
30 Replacement references will be used by default by all Git commands
31 except those doing reachability traversal (prune, pack transfer and
32 fsck).
33
34 It is possible to disable use of replacement references for any
35 command using the `--no-replace-objects` option just after 'git'.
36
37 For example if commit 'foo' has been replaced by commit 'bar':
38
39 ------------------------------------------------
40 $ git --no-replace-objects cat-file commit foo
41 ------------------------------------------------
42
43 shows information about commit 'foo', while:
44
45 ------------------------------------------------
46 $ git cat-file commit foo
47 ------------------------------------------------
48
49 shows information about commit 'bar'.
50
51 The 'GIT_NO_REPLACE_OBJECTS' environment variable can be set to
52 achieve the same effect as the `--no-replace-objects` option.
53
54 OPTIONS
55 -------
56 -f::
57         If an existing replace ref for the same object exists, it will
58         be overwritten (instead of failing).
59
60 -d::
61         Delete existing replace refs for the given objects.
62
63 -l <pattern>::
64         List replace refs for objects that match the given pattern (or
65         all if no pattern is given).
66         Typing "git replace" without arguments, also lists all replace
67         refs.
68
69 CREATING REPLACEMENT OBJECTS
70 ----------------------------
71
72 linkgit:git-filter-branch[1], linkgit:git-hash-object[1] and
73 linkgit:git-rebase[1], among other git commands, can be used to create
74 replacement objects from existing objects.
75
76 If you want to replace many blobs, trees or commits that are part of a
77 string of commits, you may just want to create a replacement string of
78 commits and then only replace the commit at the tip of the target
79 string of commits with the commit at the tip of the replacement string
80 of commits.
81
82 BUGS
83 ----
84 Comparing blobs or trees that have been replaced with those that
85 replace them will not work properly. And using `git reset --hard` to
86 go back to a replaced commit will move the branch to the replacement
87 commit instead of the replaced commit.
88
89 There may be other problems when using 'git rev-list' related to
90 pending objects.
91
92 SEE ALSO
93 --------
94 linkgit:git-hash-object[1]
95 linkgit:git-filter-branch[1]
96 linkgit:git-rebase[1]
97 linkgit:git-tag[1]
98 linkgit:git-branch[1]
99 linkgit:git[1]
100
101 GIT
102 ---
103 Part of the linkgit:git[1] suite