{
    "content": [
        {
            "type": "text",
            "text": "# git-replace (man)\n\n## NAME\n\ngit-replace - Create, list, delete refs to replace objects\n\n## SYNOPSIS\n\ngit replace [-f] <object> <replacement>\ngit replace [-f] --edit <object>\ngit replace [-f] --graft <commit> [<parent>...]\ngit replace [-f] --convert-graft-file\ngit replace -d <object>...\ngit replace [--format=<format>] [-l [<pattern>]]\n\n## DESCRIPTION\n\nAdds a replace reference in refs/replace/ namespace.\n\n## TLDR\n\n> Create, list, and delete refs to replace objects.\n\n- Replace any commit with a different one, leaving other commits unchanged:\n  `git replace {{object}} {{replacement}}`\n- Delete existing replace refs for the given objects:\n  `git replace {{-d|--delete}} {{object}}`\n- Edit an object's content interactively:\n  `git replace --edit {{object}}`\n\n*Source: tldr-pages*\n\n## Sections\n\n- **NAME**\n- **SYNOPSIS**\n- **DESCRIPTION**\n- **OPTIONS** (6 subsections)\n- **FORMATS**\n- **CREATING REPLACEMENT OBJECTS**\n- **BUGS**\n- **SEE ALSO**\n- **GIT**\n- **NOTES**\n\nUse structuredContent.sections for detailed options, examples, and full documentation.\n"
        }
    ],
    "structuredContent": {
        "command": "git-replace",
        "section": "",
        "mode": "man",
        "summary": "git-replace - Create, list, delete refs to replace objects",
        "synopsis": "git replace [-f] <object> <replacement>\ngit replace [-f] --edit <object>\ngit replace [-f] --graft <commit> [<parent>...]\ngit replace [-f] --convert-graft-file\ngit replace -d <object>...\ngit replace [--format=<format>] [-l [<pattern>]]",
        "tldr_summary": "Create, list, and delete refs to replace objects.",
        "tldr_examples": [
            {
                "description": "Replace any commit with a different one, leaving other commits unchanged",
                "command": "git replace {{object}} {{replacement}}"
            },
            {
                "description": "Delete existing replace refs for the given objects",
                "command": "git replace {{-d|--delete}} {{object}}"
            },
            {
                "description": "Edit an object's content interactively",
                "command": "git replace --edit {{object}}"
            }
        ],
        "tldr_source": "official",
        "flags": [
            {
                "flag": "-f",
                "long": "--force",
                "arg": null,
                "description": "If an existing replace ref for the same object exists, it will be overwritten (instead of failing)."
            },
            {
                "flag": "-d",
                "long": "--delete",
                "arg": null,
                "description": "Delete existing replace refs for the given objects."
            },
            {
                "flag": "",
                "long": "--edit",
                "arg": "<object>",
                "description": "Edit an object’s content interactively. The existing content for <object> is pretty-printed into a temporary file, an editor is launched on the file, and the result is parsed to create a new object of the same type as <object>. A replacement ref is then created to replace <object> with the newly created object. See git-var(1) for details about how the editor will be chosen."
            },
            {
                "flag": "",
                "long": "--raw",
                "arg": null,
                "description": "When editing, provide the raw object contents rather than pretty-printed ones. Currently this only affects trees, which will be shown in their binary form. This is harder to work with, but can help when repairing a tree that is so corrupted it cannot be pretty-printed. Note that you may need to configure your editor to cleanly read and write binary data. --graft <commit> [<parent>...] Create a graft commit. A new commit is created with the same content as <commit> except that its parents will be [<parent>...] instead of <commit>'s parents. A replacement ref is then created to replace <commit> with the newly created commit. Use --convert-graft-file to convert a $GITDIR/info/grafts file and use replace refs instead."
            },
            {
                "flag": "",
                "long": "--convert-graft-file",
                "arg": null,
                "description": "Creates graft commits for all entries in $GITDIR/info/grafts and deletes that file upon success. The purpose is to help users with transitioning off of the now-deprecated graft file."
            },
            {
                "flag": "-l",
                "long": "--list",
                "arg": "<pattern>",
                "description": "List replace refs for objects that match the given pattern (or all if no pattern is given). Typing \"git replace\" without arguments, also lists all replace refs. --format=<format> When listing, use the specified <format>, which can be one of short, medium and long. When omitted, the format defaults to short."
            }
        ],
        "examples": [],
        "see_also": [
            {
                "name": "git-hash-object",
                "section": "1",
                "url": "https://www.chedong.com/phpMan.php/man/git-hash-object/1/json"
            },
            {
                "name": "git-rebase",
                "section": "1",
                "url": "https://www.chedong.com/phpMan.php/man/git-rebase/1/json"
            },
            {
                "name": "git-tag",
                "section": "1",
                "url": "https://www.chedong.com/phpMan.php/man/git-tag/1/json"
            },
            {
                "name": "git-branch",
                "section": "1",
                "url": "https://www.chedong.com/phpMan.php/man/git-branch/1/json"
            },
            {
                "name": "git-commit",
                "section": "1",
                "url": "https://www.chedong.com/phpMan.php/man/git-commit/1/json"
            },
            {
                "name": "git-var",
                "section": "1",
                "url": "https://www.chedong.com/phpMan.php/man/git-var/1/json"
            },
            {
                "name": "git",
                "section": "1",
                "url": "https://www.chedong.com/phpMan.php/man/git/1/json"
            }
        ],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SYNOPSIS",
                "lines": 8,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 34,
                "subsections": []
            },
            {
                "name": "OPTIONS",
                "lines": 1,
                "subsections": [
                    {
                        "name": "-f, --force",
                        "lines": 3,
                        "flag": "-f",
                        "long": "--force"
                    },
                    {
                        "name": "-d, --delete",
                        "lines": 2,
                        "flag": "-d",
                        "long": "--delete"
                    },
                    {
                        "name": "--edit <object>",
                        "lines": 6,
                        "long": "--edit",
                        "arg": "<object>"
                    },
                    {
                        "name": "--raw",
                        "lines": 12,
                        "long": "--raw"
                    },
                    {
                        "name": "--convert-graft-file",
                        "lines": 4,
                        "long": "--convert-graft-file"
                    },
                    {
                        "name": "-l <pattern>, --list <pattern>",
                        "lines": 7,
                        "flag": "-l",
                        "long": "--list",
                        "arg": "<pattern>"
                    }
                ]
            },
            {
                "name": "FORMATS",
                "lines": 8,
                "subsections": []
            },
            {
                "name": "CREATING REPLACEMENT OBJECTS",
                "lines": 9,
                "subsections": []
            },
            {
                "name": "BUGS",
                "lines": 6,
                "subsections": []
            },
            {
                "name": "SEE ALSO",
                "lines": 3,
                "subsections": []
            },
            {
                "name": "GIT",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "NOTES",
                "lines": 6,
                "subsections": []
            }
        ],
        "sections": {
            "NAME": {
                "content": "git-replace - Create, list, delete refs to replace objects\n",
                "subsections": []
            },
            "SYNOPSIS": {
                "content": "git replace [-f] <object> <replacement>\ngit replace [-f] --edit <object>\ngit replace [-f] --graft <commit> [<parent>...]\ngit replace [-f] --convert-graft-file\ngit replace -d <object>...\ngit replace [--format=<format>] [-l [<pattern>]]\n\n",
                "subsections": []
            },
            "DESCRIPTION": {
                "content": "Adds a replace reference in refs/replace/ namespace.\n\nThe name of the replace reference is the SHA-1 of the object that is replaced. The content of\nthe replace reference is the SHA-1 of the replacement object.\n\nThe replaced object and the replacement object must be of the same type. This restriction can\nbe bypassed using -f.\n\nUnless -f is given, the replace reference must not yet exist.\n\nThere is no other restriction on the replaced and replacement objects. Merge commits can be\nreplaced by non-merge commits and vice versa.\n\nReplacement references will be used by default by all Git commands except those doing\nreachability traversal (prune, pack transfer and fsck).\n\nIt is possible to disable use of replacement references for any command using the\n--no-replace-objects option just after git.\n\nFor example if commit foo has been replaced by commit bar:\n\n$ git --no-replace-objects cat-file commit foo\n\n\nshows information about commit foo, while:\n\n$ git cat-file commit foo\n\n\nshows information about commit bar.\n\nThe GITNOREPLACEOBJECTS environment variable can be set to achieve the same effect as the\n--no-replace-objects option.\n",
                "subsections": []
            },
            "OPTIONS": {
                "content": "",
                "subsections": [
                    {
                        "name": "-f, --force",
                        "content": "If an existing replace ref for the same object exists, it will be overwritten (instead of\nfailing).\n",
                        "flag": "-f",
                        "long": "--force"
                    },
                    {
                        "name": "-d, --delete",
                        "content": "Delete existing replace refs for the given objects.\n",
                        "flag": "-d",
                        "long": "--delete"
                    },
                    {
                        "name": "--edit <object>",
                        "content": "Edit an object’s content interactively. The existing content for <object> is\npretty-printed into a temporary file, an editor is launched on the file, and the result\nis parsed to create a new object of the same type as <object>. A replacement ref is then\ncreated to replace <object> with the newly created object. See git-var(1) for details\nabout how the editor will be chosen.\n",
                        "long": "--edit",
                        "arg": "<object>"
                    },
                    {
                        "name": "--raw",
                        "content": "When editing, provide the raw object contents rather than pretty-printed ones. Currently\nthis only affects trees, which will be shown in their binary form. This is harder to work\nwith, but can help when repairing a tree that is so corrupted it cannot be\npretty-printed. Note that you may need to configure your editor to cleanly read and write\nbinary data.\n\n--graft <commit> [<parent>...]\nCreate a graft commit. A new commit is created with the same content as <commit> except\nthat its parents will be [<parent>...] instead of <commit>'s parents. A replacement ref\nis then created to replace <commit> with the newly created commit. Use\n--convert-graft-file to convert a $GITDIR/info/grafts file and use replace refs instead.\n",
                        "long": "--raw"
                    },
                    {
                        "name": "--convert-graft-file",
                        "content": "Creates graft commits for all entries in $GITDIR/info/grafts and deletes that file upon\nsuccess. The purpose is to help users with transitioning off of the now-deprecated graft\nfile.\n",
                        "long": "--convert-graft-file"
                    },
                    {
                        "name": "-l <pattern>, --list <pattern>",
                        "content": "List replace refs for objects that match the given pattern (or all if no pattern is\ngiven). Typing \"git replace\" without arguments, also lists all replace refs.\n\n--format=<format>\nWhen listing, use the specified <format>, which can be one of short, medium and long.\nWhen omitted, the format defaults to short.\n",
                        "flag": "-l",
                        "long": "--list",
                        "arg": "<pattern>"
                    }
                ]
            },
            "FORMATS": {
                "content": "The following format are available:\n\n•   short: <replaced sha1>\n\n•   medium: <replaced sha1> → <replacement sha1>\n\n•   long: <replaced sha1> (<replaced type>) → <replacement sha1> (<replacement type>)\n",
                "subsections": []
            },
            "CREATING REPLACEMENT OBJECTS": {
                "content": "git-hash-object(1), git-rebase(1), and git-filter-repo[1], among other git commands, can be\nused to create replacement objects from existing objects. The --edit option can also be used\nwith git replace to create a replacement object by editing an existing object.\n\nIf you want to replace many blobs, trees or commits that are part of a string of commits, you\nmay just want to create a replacement string of commits and then only replace the commit at\nthe tip of the target string of commits with the commit at the tip of the replacement string\nof commits.\n",
                "subsections": []
            },
            "BUGS": {
                "content": "Comparing blobs or trees that have been replaced with those that replace them will not work\nproperly. And using git reset --hard to go back to a replaced commit will move the branch to\nthe replacement commit instead of the replaced commit.\n\nThere may be other problems when using git rev-list related to pending objects.\n",
                "subsections": []
            },
            "SEE ALSO": {
                "content": "git-hash-object(1) git-rebase(1) git-tag(1) git-branch(1) git-commit(1) git-var(1) git(1)\ngit-filter-repo[1]\n",
                "subsections": []
            },
            "GIT": {
                "content": "Part of the git(1) suite\n",
                "subsections": []
            },
            "NOTES": {
                "content": "1. git-filter-repo\nhttps://github.com/newren/git-filter-repo\n\n\n\nGit 2.34.1                                   02/26/2026                               GIT-REPLACE(1)",
                "subsections": []
            }
        }
    }
}