git-replace.txt 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. git-replace(1)
  2. ==============
  3. NAME
  4. ----
  5. git-replace - Create, list, delete refs to replace objects
  6. SYNOPSIS
  7. --------
  8. [verse]
  9. 'git replace' [-f] <object> <replacement>
  10. 'git replace' [-f] --edit <object>
  11. 'git replace' [-f] --graft <commit> [<parent>...]
  12. 'git replace' [-f] --convert-graft-file
  13. 'git replace' -d <object>...
  14. 'git replace' [--format=<format>] [-l [<pattern>]]
  15. DESCRIPTION
  16. -----------
  17. Adds a 'replace' reference in `refs/replace/` namespace.
  18. The name of the 'replace' reference is the SHA-1 of the object that is
  19. replaced. The content of the 'replace' reference is the SHA-1 of the
  20. replacement object.
  21. The replaced object and the replacement object must be of the same type.
  22. This restriction can be bypassed using `-f`.
  23. Unless `-f` is given, the 'replace' reference must not yet exist.
  24. There is no other restriction on the replaced and replacement objects.
  25. Merge commits can be replaced by non-merge commits and vice versa.
  26. Replacement references will be used by default by all Git commands
  27. except those doing reachability traversal (prune, pack transfer and
  28. fsck).
  29. It is possible to disable use of replacement references for any
  30. command using the `--no-replace-objects` option just after 'git'.
  31. For example if commit 'foo' has been replaced by commit 'bar':
  32. ------------------------------------------------
  33. $ git --no-replace-objects cat-file commit foo
  34. ------------------------------------------------
  35. shows information about commit 'foo', while:
  36. ------------------------------------------------
  37. $ git cat-file commit foo
  38. ------------------------------------------------
  39. shows information about commit 'bar'.
  40. The `GIT_NO_REPLACE_OBJECTS` environment variable can be set to
  41. achieve the same effect as the `--no-replace-objects` option.
  42. OPTIONS
  43. -------
  44. -f::
  45. --force::
  46. If an existing replace ref for the same object exists, it will
  47. be overwritten (instead of failing).
  48. -d::
  49. --delete::
  50. Delete existing replace refs for the given objects.
  51. --edit <object>::
  52. Edit an object's content interactively. The existing content
  53. for <object> is pretty-printed into a temporary file, an
  54. editor is launched on the file, and the result is parsed to
  55. create a new object of the same type as <object>. A
  56. replacement ref is then created to replace <object> with the
  57. newly created object. See linkgit:git-var[1] for details about
  58. how the editor will be chosen.
  59. --raw::
  60. When editing, provide the raw object contents rather than
  61. pretty-printed ones. Currently this only affects trees, which
  62. will be shown in their binary form. This is harder to work with,
  63. but can help when repairing a tree that is so corrupted it
  64. cannot be pretty-printed. Note that you may need to configure
  65. your editor to cleanly read and write binary data.
  66. --graft <commit> [<parent>...]::
  67. Create a graft commit. A new commit is created with the same
  68. content as <commit> except that its parents will be
  69. [<parent>...] instead of <commit>'s parents. A replacement ref
  70. is then created to replace <commit> with the newly created
  71. commit. Use `--convert-graft-file` to convert a
  72. `$GIT_DIR/info/grafts` file and use replace refs instead.
  73. --convert-graft-file::
  74. Creates graft commits for all entries in `$GIT_DIR/info/grafts`
  75. and deletes that file upon success. The purpose is to help users
  76. with transitioning off of the now-deprecated graft file.
  77. -l <pattern>::
  78. --list <pattern>::
  79. List replace refs for objects that match the given pattern (or
  80. all if no pattern is given).
  81. Typing "git replace" without arguments, also lists all replace
  82. refs.
  83. --format=<format>::
  84. When listing, use the specified <format>, which can be one of
  85. 'short', 'medium' and 'long'. When omitted, the format
  86. defaults to 'short'.
  87. FORMATS
  88. -------
  89. The following format are available:
  90. * 'short':
  91. <replaced sha1>
  92. * 'medium':
  93. <replaced sha1> -> <replacement sha1>
  94. * 'long':
  95. <replaced sha1> (<replaced type>) -> <replacement sha1> (<replacement type>)
  96. CREATING REPLACEMENT OBJECTS
  97. ----------------------------
  98. linkgit:git-hash-object[1], linkgit:git-rebase[1], and
  99. https://github.com/newren/git-filter-repo[git-filter-repo], among other git commands, can be used to
  100. create replacement objects from existing objects. The `--edit` option
  101. can also be used with 'git replace' to create a replacement object by
  102. editing an existing object.
  103. If you want to replace many blobs, trees or commits that are part of a
  104. string of commits, you may just want to create a replacement string of
  105. commits and then only replace the commit at the tip of the target
  106. string of commits with the commit at the tip of the replacement string
  107. of commits.
  108. BUGS
  109. ----
  110. Comparing blobs or trees that have been replaced with those that
  111. replace them will not work properly. And using `git reset --hard` to
  112. go back to a replaced commit will move the branch to the replacement
  113. commit instead of the replaced commit.
  114. There may be other problems when using 'git rev-list' related to
  115. pending objects.
  116. SEE ALSO
  117. --------
  118. linkgit:git-hash-object[1]
  119. linkgit:git-rebase[1]
  120. linkgit:git-tag[1]
  121. linkgit:git-branch[1]
  122. linkgit:git-commit[1]
  123. linkgit:git-var[1]
  124. linkgit:git[1]
  125. https://github.com/newren/git-filter-repo[git-filter-repo]
  126. GIT
  127. ---
  128. Part of the linkgit:git[1] suite