Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to cherry-pick the last sha from another branch in Git with 1 command?

I find myself doing this a lot when cherry-picking a commit from another branch.

$ git log -1 another_branch commit <commit_sha> // copy <commit_sha> $ git cherry-pick <commit_sha> 

Can I do all of this in one command, if so, what is it?

like image 560
FoxyGio Avatar asked Jan 01 '14 20:01

FoxyGio


People also ask

What does the given command do git cherry pick Sha?

git cherry-pick is a powerful command that enables arbitrary Git commits to be picked by reference and appended to the current working HEAD. Cherry picking is the act of picking a commit from a branch and applying it to another. git cherry-pick can be useful for undoing changes.

How do you cherry pick a commit from another branch using TortoiseGit?

Cherry-picking in TortoiseGit is invoked from the Revision Log Dialog. Within this dialog, select the commit(s) to cherry-pick, then right-click on one of the selected commits to pop up the context menu. Select Cherry Pick this commit... (or Cherry Pick select commits... if more than one commit is selected).


1 Answers

Just go with:

$ git cherry-pick another_branch 

This will cherry-pick the last commit from another_branch.

Branches in git are just references to the last commit in that branch, you can use them instead of commit SHAs in your commands.

like image 81
pbetkier Avatar answered Oct 05 '22 12:10

pbetkier