02
Dec
Learn how to git:merge a single commit
Sometimes, you may have one commit you want to get into production, but it’s located after other changes that you’re not ready to merge in yet. How can you get that single git commit into a different branch?
First, you have to know the SHA of the commit you want:
git checkout goto-branch-with-commit-you-want-to-go-live git log
Then, checkout master and use following steps.
git checkout master # -n => don't commit, just merge changes so we can review and commit ourself git cherry-pick -n [The commit’s SHA-1 Hash] # review git diff –cached # commit if all is well git commit -a -m “merge SHA1 ..."
If you’re feeling confident, you can skip the -n and merge the single commit in directly and save a minute. Note, this isn’t a merge, so it’s possible you could have some conflicts down the road when you merge the original commit into this branch. You’re creating a brand new commit object.