Menu
×
   ❮     
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP C C++ C# AWS W3.CSS HOW TO BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS DSA TYPESCRIPT ANGULAR ANGULARJS GIT POSTGRESQL MONGODB ASP AI R GO KOTLIN SWIFT SASS VUE GEN AI SCIPY CYBERSECURITY DATA SCIENCE INTRO TO PROGRAMMING INTRO TO HTML & CSS BASH RUST TOOLS

Git Tutorial

Git HOME Git Intro Git Install Git Config Git Get Started Git New Files Git Staging Git Commit Git Remove and Move Git Tagging Git Stash Git History Git Diff Git Blame Git Help Git Branch Git Merge Git Workflow Git Best Practices

Git and GitHub

GitHub Get Started Git What is SSH? GitHub Add SSH GitHub Set Remote GitHub Edit Code Pull from GitHub Push to GitHub GitHub Branch Pull Branch from GitHub Push Branch to GitHub GitHub Flow GitHub Pages Git GUI Clients

Git Contribute

GitHub Fork Git Clone from GitHub GitHub Send Pull Request

Git Undo

Git Revert Git Reset Git Clean Git Amend Git Rebase Git Reflog Git Recovery

Git Advanced

Git .gitignore Git .gitattributes Git Large File Storage (LFS) Git Signing Commits/Tags Git Cherrypick & Patch Git Bisect Git Merge Conflicts Git CI/CD Git Hooks Git Submodules Git Worktree Git Remote Advanced

Git and Bitbucket

Bitbucket Get Started Bitbucket Add SSH Bitbucket Set Remote Bitbucket Edit Code Bitbucket Branch Bitbucket Pages Bitbucket Fork Git Clone from Bitbucket Bitbucket Send Pull Request

Git and GitLab

GitLab Get Started GitLab Add SSH GitLab Set Remote GitLab Edit Code GitLab Branch GitLab Pages GitLab Fork Git Clone from GitLab GitLab Send Pull Request

Git Cert

Git Certificate

Git Reference

Git Glossary

Git Exercises

Git Terminal Git Exercises Git Challenges Git Quiz Git Syllabus Git Study Plan

Git Cherry-pick & Patch


Share

What is Cherry-pick?

Cherry-pick lets you copy a single commit from one branch to another. It's useful when you want just one (or a few) changes, not everything from another branch.


What is a Patch?

A patch is a file with changes from one or more commits. You can share a patch or apply it to another repository, even if it's unrelated to your own.


When to Use Each

  • Use cherry-pick to copy a commit between branches in the same repository.
  • Use patches to share changes as files, or when working across different repositories.

How to Cherry-pick a Commit

Copy a specific commit from another branch to your current branch:

Example: Cherry-pick a Commit

git cherry-pick abc1234
Try it Yourself »

This creates a new commit on your branch with the same changes.



Edit the Commit Message

Use --edit to change the commit message while cherry-picking:

Example: Edit Commit Message

git cherry-pick abc1234 --edit

Apply Without Committing

Use --no-commit (or -n) to apply the changes, but not create a commit yet. This lets you make more changes before committing:

Example: Cherry-pick Without Commit

git cherry-pick abc1234 --no-commit
Try it Yourself »

Add Commit Origin

Use -x to add a line to the commit message showing where the commit came from:

Example: Cherry-pick With Origin

git cherry-pick abc1234 -x
Try it Yourself »

Handling Conflicts

If there are conflicts, Git will pause and ask you to fix them. After fixing, run:

Example: Continue After Conflict

git add .
git cherry-pick --continue
Try it Yourself »

To cancel the cherry-pick, use:

Example: Abort Cherry-pick

git cherry-pick --abort
Try it Yourself »

How to Create a Patch

Make a patch file from a commit:

Example: Create Patch

git format-patch -1 abc1234
Try it Yourself »

For multiple commits:

Example: Multiple Commits

git format-patch HEAD~3
0001-Add-style.css.patch
0002-Style-the-heading.patch
0003-Add-a-welcome-line.patch
Try it Yourself »

How to Apply a Patch

Apply a patch file to your current branch:

Example: Apply Patch

git apply 0001-some-change.patch
Try it Yourself »

Apply a Patch and Keep Metadata

Use git am to apply a patch and keep the original author and message:

Example: Apply Patch with Metadata

git am 0001-some-change.patch
Applying: some change
Try it Yourself »

Reverse a Patch

Undo the changes in a patch file:

Example: Reverse Patch

git apply -R 0001-some-change.patch
Try it Yourself »

Tip: Use cherry-pick for copying a single commit in the same repository.

Use patches to share changes as files or work across repositories.

If you want to keep commit history and authors, use git am instead of git apply.


Troubleshooting & Best Practices

  • Cherry-pick conflicts: If you get conflicts, fix them, then run git cherry-pick --continue.
    Abort with git cherry-pick --abort if needed.
  • Patch doesn't apply cleanly: Make sure the patch matches your codebase. Sometimes you may need to adjust manually.
  • Keep your branches up to date: Before cherry-picking or applying patches, pull the latest changes.



Free account

Track your progress

XP earned 0 Day streak 0 Spaces 0 League —

New

Learn in Adventure Mode W3Schools Adventure App

Coding fundamentals as bite-sized lessons and challenges.

×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
sales@w3schools.com

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
help@w3schools.com

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookies and privacy policy.

Copyright 1999-2026 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.