git-replace
创建、列出、删除替换对象的引用。
概要
bash
'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>]]描述
在 refs/replace/ 命名空间中添加一个 replace 引用。
replace 引用的名称是被替换对象的 SHA-1。replace 引用的内容是替换对象的 SHA-1。
被替换对象和替换对象必须是同一类型。此限制可以使用 -f 绕过。
除非给出 -f,否则 replace 引用必须尚不存在。
被替换对象和替换对象没有其他限制。合并提交可以被非合并提交替换,反之亦然。
替换引用默认将被所有 Git 命令使用,除了那些执行可达性遍历的命令(prune、pack 传输和 fsck)。
可以使用 --no-replace-objects 选项在 git 之后禁用任何命令使用替换引用。
例如,如果提交 'foo' 已被提交 'bar' 替换:
bash
$ git --no-replace-objects cat-file commit foo显示有关提交 'foo' 的信息,而:
bash
$ git cat-file commit foo显示有关提交 'bar' 的信息。
选项
-f, --force:如果同一对象存在现有的 replace 引用,它将被覆盖。-d, --delete:删除给定对象的现有 replace 引用。--edit <object>:交互式编辑对象的内容。--raw:编辑时提供原始对象内容而不是格式化的内容。--graft <commit> [<parent>...]:创建 graft 提交。--convert-graft-file:为$GIT_DIR/info/grafts中的所有条目创建 graft 提交,并在成功后删除该文件。-l <pattern>, --list <pattern>:列出匹配给定模式的对象的 replace 引用。--format=<format>:列出时使用指定的格式,可以是short、medium和long之一。
格式
short:<replaced-sha1>medium:<replaced-sha1> -> <replacement-sha1>long:<replaced-sha1> (<replaced-type>) -> <replacement-sha1> (<replacement-type>)
创建替换对象
git-hash-object(1)、git-rebase(1) 和 git-filter-repo 等 Git 命令可用于从现有对象创建替换对象。
已知问题
比较已被替换的 blob 或树与替换它们的对象将无法正常工作。使用 git reset --hard 返回到被替换的提交将把分支移动到替换提交而不是被替换的提交。
注意事项
替换对象或 commit grafts 的存在会关闭对 commit-graph 的读取或写入,这可能会导致性能问题。
另请参阅
git-hash-object(1), git-rebase(1), git-tag(1), git-branch(1), git-commit(1)
Git
git 套件的一部分
