Join egghead, unlock knowledge.

Want more egghead?

This lesson is for members. Join us? Get access to all 3,000+ tutorials + a community with expert developers around the world.

Unlock This Lesson
Become a member
to unlock all features

Level Up!

Access all courses & lessons on egghead today and lock-in your price for life.


    Copy a Commit from One Branch to Another

    Chris AchardChris Achard

    If you want to pull over just a single commit from one branch onto another, you can do that with git cherry-pick [HASH-TO-MOVE]

    We'll demonstrate that by making a commit on a feature branch, and then copying that commit (but not the entire branch) onto master.



    Become a Member to view code

    You must be a Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson




    Instructor: If we do git branch, we see we have two different branches here. If we do git log one line, we can see that our latest branch has adsHelloWorld as the commit, and that is diverse from master, which is the reversion of the take three commit.

    This is our app.js on the JSChanges branch. Let's check out master. Now our app.js is empty. Let's say we're on master and we really want that function on master, but we don't want to pull over the entire JSChanges branch yet. What we really want is just to pick this commit and move it over to master.

    If we do a git log one line now, we see that the latest is revert take three, and we want this adsHelloWorld. We're going to get the hash of the commit that we want, and we're going to do git cherry-pick, and then we're going to do the hash that we want.

    If we do a git log one line, we can see that our head is pointing at adsHelloWorld, but the hash is different. It's made a new commit hash as it came over and we have our function here.

    If we are happy with what we have now, we can do a git push. Now, we've copied the commit from js.changes over the master and pushed it up. The commit now exists in both trees.