Junio C Hamano | fe24db0 | 2009-08-22 05:10:47 | [diff] [blame] | 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> |
Junio C Hamano | c8c398a | 2014-06-16 21:14:05 | [diff] [blame] | 12 | 'git replace' [-f] --edit <object> |
Junio C Hamano | d9421af | 2014-07-27 23:13:00 | [diff] [blame] | 13 | 'git replace' [-f] --graft <commit> [<parent>...] |
Junio C Hamano | b9d9d90 | 2018-05-23 07:07:42 | [diff] [blame] | 14 | 'git replace' [-f] --convert-graft-file |
Junio C Hamano | fe24db0 | 2009-08-22 05:10:47 | [diff] [blame] | 15 | 'git replace' -d <object>... |
Junio C Hamano | 21bc18b | 2014-01-10 20:33:07 | [diff] [blame] | 16 | 'git replace' [--format=<format>] [-l [<pattern>]] |
Junio C Hamano | fe24db0 | 2009-08-22 05:10:47 | [diff] [blame] | 17 | |
| 18 | DESCRIPTION |
| 19 | ----------- |
Junio C Hamano | d031611 | 2012-08-22 19:55:29 | [diff] [blame] | 20 | Adds a 'replace' reference in `refs/replace/` namespace. |
Junio C Hamano | fe24db0 | 2009-08-22 05:10:47 | [diff] [blame] | 21 | |
Junio C Hamano | e3f080d | 2013-04-22 02:27:13 | [diff] [blame] | 22 | The name of the 'replace' reference is the SHA-1 of the object that is |
| 23 | replaced. The content of the 'replace' reference is the SHA-1 of the |
Junio C Hamano | fe24db0 | 2009-08-22 05:10:47 | [diff] [blame] | 24 | replacement object. |
| 25 | |
Junio C Hamano | 369e340 | 2013-10-15 18:40:25 | [diff] [blame] | 26 | The replaced object and the replacement object must be of the same type. |
| 27 | This restriction can be bypassed using `-f`. |
| 28 | |
Junio C Hamano | d031611 | 2012-08-22 19:55:29 | [diff] [blame] | 29 | Unless `-f` is given, the 'replace' reference must not yet exist. |
Junio C Hamano | fe24db0 | 2009-08-22 05:10:47 | [diff] [blame] | 30 | |
Junio C Hamano | 369e340 | 2013-10-15 18:40:25 | [diff] [blame] | 31 | There is no other restriction on the replaced and replacement objects. |
| 32 | Merge commits can be replaced by non-merge commits and vice versa. |
| 33 | |
Junio C Hamano | 076ffcc | 2013-02-06 05:13:21 | [diff] [blame] | 34 | Replacement references will be used by default by all Git commands |
Junio C Hamano | 5706e0b | 2009-11-24 10:54:16 | [diff] [blame] | 35 | except those doing reachability traversal (prune, pack transfer and |
| 36 | fsck). |
Junio C Hamano | 3d23a0a | 2009-10-19 08:04:30 | [diff] [blame] | 37 | |
Junio C Hamano | 5706e0b | 2009-11-24 10:54:16 | [diff] [blame] | 38 | It is possible to disable use of replacement references for any |
| 39 | command using the `--no-replace-objects` option just after 'git'. |
Junio C Hamano | 3d23a0a | 2009-10-19 08:04:30 | [diff] [blame] | 40 | |
Junio C Hamano | 5706e0b | 2009-11-24 10:54:16 | [diff] [blame] | 41 | For example if commit 'foo' has been replaced by commit 'bar': |
Junio C Hamano | 3d23a0a | 2009-10-19 08:04:30 | [diff] [blame] | 42 | |
| 43 | ------------------------------------------------ |
Junio C Hamano | 5706e0b | 2009-11-24 10:54:16 | [diff] [blame] | 44 | $ git --no-replace-objects cat-file commit foo |
Junio C Hamano | 3d23a0a | 2009-10-19 08:04:30 | [diff] [blame] | 45 | ------------------------------------------------ |
| 46 | |
Junio C Hamano | 5706e0b | 2009-11-24 10:54:16 | [diff] [blame] | 47 | shows information about commit 'foo', while: |
Junio C Hamano | 3d23a0a | 2009-10-19 08:04:30 | [diff] [blame] | 48 | |
| 49 | ------------------------------------------------ |
| 50 | $ git cat-file commit foo |
| 51 | ------------------------------------------------ |
| 52 | |
Junio C Hamano | 5706e0b | 2009-11-24 10:54:16 | [diff] [blame] | 53 | shows information about commit 'bar'. |
| 54 | |
Junio C Hamano | 042f214 | 2016-06-27 18:05:05 | [diff] [blame] | 55 | The `GIT_NO_REPLACE_OBJECTS` environment variable can be set to |
Junio C Hamano | 5706e0b | 2009-11-24 10:54:16 | [diff] [blame] | 56 | achieve the same effect as the `--no-replace-objects` option. |
Junio C Hamano | 3d23a0a | 2009-10-19 08:04:30 | [diff] [blame] | 57 | |
Junio C Hamano | fe24db0 | 2009-08-22 05:10:47 | [diff] [blame] | 58 | OPTIONS |
| 59 | ------- |
| 60 | -f:: |
Junio C Hamano | 369e340 | 2013-10-15 18:40:25 | [diff] [blame] | 61 | --force:: |
Junio C Hamano | fe24db0 | 2009-08-22 05:10:47 | [diff] [blame] | 62 | If an existing replace ref for the same object exists, it will |
| 63 | be overwritten (instead of failing). |
| 64 | |
| 65 | -d:: |
Junio C Hamano | 369e340 | 2013-10-15 18:40:25 | [diff] [blame] | 66 | --delete:: |
Junio C Hamano | fe24db0 | 2009-08-22 05:10:47 | [diff] [blame] | 67 | Delete existing replace refs for the given objects. |
| 68 | |
Junio C Hamano | c8c398a | 2014-06-16 21:14:05 | [diff] [blame] | 69 | --edit <object>:: |
| 70 | Edit an object's content interactively. The existing content |
| 71 | for <object> is pretty-printed into a temporary file, an |
| 72 | editor is launched on the file, and the result is parsed to |
| 73 | create a new object of the same type as <object>. A |
| 74 | replacement ref is then created to replace <object> with the |
| 75 | newly created object. See linkgit:git-var[1] for details about |
| 76 | how the editor will be chosen. |
| 77 | |
Junio C Hamano | 6f0c944 | 2014-07-16 21:51:32 | [diff] [blame] | 78 | --raw:: |
| 79 | When editing, provide the raw object contents rather than |
| 80 | pretty-printed ones. Currently this only affects trees, which |
| 81 | will be shown in their binary form. This is harder to work with, |
| 82 | but can help when repairing a tree that is so corrupted it |
| 83 | cannot be pretty-printed. Note that you may need to configure |
| 84 | your editor to cleanly read and write binary data. |
| 85 | |
Junio C Hamano | d9421af | 2014-07-27 23:13:00 | [diff] [blame] | 86 | --graft <commit> [<parent>...]:: |
| 87 | Create a graft commit. A new commit is created with the same |
| 88 | content as <commit> except that its parents will be |
| 89 | [<parent>...] instead of <commit>'s parents. A replacement ref |
| 90 | is then created to replace <commit> with the newly created |
Junio C Hamano | b9d9d90 | 2018-05-23 07:07:42 | [diff] [blame] | 91 | commit. Use `--convert-graft-file` to convert a |
| 92 | `$GIT_DIR/info/grafts` file and use replace refs instead. |
| 93 | |
| 94 | --convert-graft-file:: |
| 95 | Creates graft commits for all entries in `$GIT_DIR/info/grafts` |
| 96 | and deletes that file upon success. The purpose is to help users |
| 97 | with transitioning off of the now-deprecated graft file. |
Junio C Hamano | d9421af | 2014-07-27 23:13:00 | [diff] [blame] | 98 | |
Junio C Hamano | fe24db0 | 2009-08-22 05:10:47 | [diff] [blame] | 99 | -l <pattern>:: |
Junio C Hamano | 369e340 | 2013-10-15 18:40:25 | [diff] [blame] | 100 | --list <pattern>:: |
Junio C Hamano | fe24db0 | 2009-08-22 05:10:47 | [diff] [blame] | 101 | List replace refs for objects that match the given pattern (or |
| 102 | all if no pattern is given). |
| 103 | Typing "git replace" without arguments, also lists all replace |
| 104 | refs. |
| 105 | |
Junio C Hamano | 21bc18b | 2014-01-10 20:33:07 | [diff] [blame] | 106 | --format=<format>:: |
| 107 | When listing, use the specified <format>, which can be one of |
| 108 | 'short', 'medium' and 'long'. When omitted, the format |
| 109 | defaults to 'short'. |
| 110 | |
| 111 | FORMATS |
| 112 | ------- |
| 113 | |
| 114 | The 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 Hamano | 369e340 | 2013-10-15 18:40:25 | [diff] [blame] | 123 | CREATING REPLACEMENT OBJECTS |
| 124 | ---------------------------- |
| 125 | |
| 126 | linkgit:git-filter-branch[1], linkgit:git-hash-object[1] and |
| 127 | linkgit:git-rebase[1], among other git commands, can be used to create |
Junio C Hamano | c8c398a | 2014-06-16 21:14:05 | [diff] [blame] | 128 | replacement objects from existing objects. The `--edit` option can |
| 129 | also be used with 'git replace' to create a replacement object by |
| 130 | editing an existing object. |
Junio C Hamano | 369e340 | 2013-10-15 18:40:25 | [diff] [blame] | 131 | |
| 132 | If you want to replace many blobs, trees or commits that are part of a |
| 133 | string of commits, you may just want to create a replacement string of |
| 134 | commits and then only replace the commit at the tip of the target |
| 135 | string of commits with the commit at the tip of the replacement string |
| 136 | of commits. |
| 137 | |
Junio C Hamano | fe24db0 | 2009-08-22 05:10:47 | [diff] [blame] | 138 | BUGS |
| 139 | ---- |
| 140 | Comparing blobs or trees that have been replaced with those that |
Junio C Hamano | 1aa40d2 | 2010-01-21 17:46:43 | [diff] [blame] | 141 | replace them will not work properly. And using `git reset --hard` to |
Junio C Hamano | fe24db0 | 2009-08-22 05:10:47 | [diff] [blame] | 142 | go back to a replaced commit will move the branch to the replacement |
| 143 | commit instead of the replaced commit. |
| 144 | |
| 145 | There may be other problems when using 'git rev-list' related to |
Junio C Hamano | 369e340 | 2013-10-15 18:40:25 | [diff] [blame] | 146 | pending objects. |
Junio C Hamano | fe24db0 | 2009-08-22 05:10:47 | [diff] [blame] | 147 | |
| 148 | SEE ALSO |
| 149 | -------- |
Junio C Hamano | 369e340 | 2013-10-15 18:40:25 | [diff] [blame] | 150 | linkgit:git-hash-object[1] |
| 151 | linkgit:git-filter-branch[1] |
| 152 | linkgit:git-rebase[1] |
Junio C Hamano | fe24db0 | 2009-08-22 05:10:47 | [diff] [blame] | 153 | linkgit:git-tag[1] |
| 154 | linkgit:git-branch[1] |
Junio C Hamano | c8c398a | 2014-06-16 21:14:05 | [diff] [blame] | 155 | linkgit:git-commit[1] |
| 156 | linkgit:git-var[1] |
Junio C Hamano | 3d23a0a | 2009-10-19 08:04:30 | [diff] [blame] | 157 | linkgit:git[1] |
Junio C Hamano | fe24db0 | 2009-08-22 05:10:47 | [diff] [blame] | 158 | |
Junio C Hamano | fe24db0 | 2009-08-22 05:10:47 | [diff] [blame] | 159 | GIT |
| 160 | --- |
| 161 | Part of the linkgit:git[1] suite |