LinuxCommandLibrary

git-graft

Manually define parent commits for initial history

TLDR

Merge all commits not present on the target branch from the source branch to target branch, and delete the source branch

$ git graft [source_branch] [target_branch]
copy

SYNOPSIS

git graft [--index] [--] <commit> [<commit> ...]

PARAMETERS

--index
    Store graft as a replace ref in the index instead of .git/info/grafts.

--
    Separates options from commit arguments.

DESCRIPTION

git graft (historically invoked via git-graft) was a deprecated Git plumbing command for creating local "graft points" to simulate parent-child relationships between commits. This tricked Git tools like git log, gitk, and git merge-base into treating disconnected histories as unified, without altering commit objects.

Grafts proved useful for scenarios like importing repositories from other VCS (e.g., SVN), recovering lost history merges, or linking parallel developments. The command appended or modified entries in the local .git/info/grafts file, where each line specifies a commit followed by its artificial parents: <commit> <parent1> <parent2> ....

Unlike true merges, grafts are purely cosmetic for history traversal and do not propagate on clone or push. They override only first-parent info for relevant operations.

Deprecated due to limitations and superseded by git replace --graft, which uses refs/replace/ for shareable, ref-like behavior. Grafts remain readable by modern Git for compatibility but writing via this command fails post-removal.

CAVEATS

Deprecated since Git 2.13.0 (2017), removed in 2.22.0 (2019). Use git replace --graft instead.

Grafts are local-only, non-shareable, and ignored by some commands. Manually edit .git/info/grafts to remove.

AFFECTED FILES

Modifies .git/info/grafts (one line per graft: <commit> <parent1> ...).

EXAMPLE

git graft abc123 def456
Sets abc123's sole parent as def456 for history walks.

HISTORY

Created in early Git (2005-2006) by Linus Torvalds et al. for ad-hoc history fixes. Deprecated in Git 2.13.0 favoring replace refs; fully removed in 2.22.0 with .git/info/grafts still supported for reading.

SEE ALSO

Copied to clipboard