Forrest logo
back to the git tool

git-graft:tldr:349a5

git-graft: 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}
try on your machine

The command git graft ${source_branch} ${target_branch} was a deprecated feature in Git but has been removed in recent versions (since Git 2.9). However, let's explain what it used to do:

In Git, grafting was a way to create a new commit that combined the history of two branches. The git graft command allowed you to graft a commit from the source branch onto the target branch, making it appear as if the changes from the source branch had always been part of the target branch's history.

The ${source_branch} and ${target_branch} are placeholders for the actual branch names or commit hashes.

Here's how it worked:

  1. The command would find the earliest common ancestor commit between the source branch and the target branch.
  2. Then, the changes introduced by the source branch since the common ancestor commit would be applied onto the target branch as a new commit.
  3. The new commit would have the same content as the source branch's commit but a different commit hash.

This way, the history of the target branch appeared to have incorporated changes from the source branch as though they had been there from the beginning.

However, this command was deprecated because the same result can be achieved using more modern techniques like git cherry-pick or git rebase.

This explanation was created by an AI. In most cases those are correct. But please always be careful and never run a command you are not sure if it is safe.
back to the git tool