git cherry-pick --no-commit <commit>

Apply the changes from a specific commit to the current branch without creating a new commit.

This command lets you bring the changes from one existing commit into your current branch while keeping them staged and editable before you decide how (or whether) to commit them.

It uses cherry-pick to copy the diff introduced by <commit> onto your current HEAD, and the --no-commit (same as -n) flag tells Git to apply those changes to the working tree and index but stop before creating a new commit, so you can review, adjust, or combine them with other changes; <commit> can be any commit hash, tag, or reference (for example a1b2c3d, feature-start, or HEAD~2). During this process, Git merges the changes from the selected commit into your current branch state; if there are conflicts, it pauses for you to resolve them before proceeding, still without auto-committing.

You can follow this command with git commit to create a single commit from the staged changes, or continue by running more git cherry-pick --no-commit <other-commit> commands to accumulate multiple commits’ changes into one combined commit, and if you decide you don’t want the applied changes you can reset them with git reset --hard (to drop both staged and unstaged changes) or git reset (to keep the changes only in the working tree). This behavior contrasts with a plain git cherry-pick <commit> (without --no-commit), which immediately creates a new commit, and with git cherry-pick -x <commit> which adds a reference note in the commit message to the original commit while still auto-committing.

Closely related variations include git cherry-pick -n <commit> which is just a shorter form of the same command, and git cherry-pick <start-commit>^..<end-commit> with -n to apply a range of commits without committing each one individually so you can squash them into a single commit with a final git commit; complementary commands include git reset --soft HEAD~1 (to undo a cherry-pick that already committed but keep changes staged), and git show <commit> or git log --oneline to inspect and pick the right commit to apply.

Examples:

  • git cherry-pick --no-commit a1b2c3d4
  • git cherry-pick -n feature-start
  • git cherry-pick -n 1234abcd
Manual page
git cherry-pick
Related commands

Welcome to GitExamples!

Sign in to gitexamples