Reputation: 5595
I have two branches, brA and brB. Every change I make in brA needs to get cherry picked into brB. My desired workflow runs entirely from the command line and uses as few keystrokes as possible
git commit -m
" = 13 + my commit message.co
aliased to checkout
and only the two branches so "git co -
" = 8cp
aliased to cherry-pick
but I don't know how to reference the last commit on another branch. Yes, I could just copy and paste the commit id or use a GUI but I'm a developer goddamit and ain't nobody got time for that!Upvotes: 1
Views: 1133
Reputation: 20118
A branch in git is nothing more but a reference on a commit; each commit has a reference on its parent commit(s) and this is how git builds the history.
When you make a commit on a branch then the reference points to the new commit which has the previous commit as its parent. This effectively means that a branch always points to the "latest" commit.
Obviously it's possible that you reset a branch and "undo" some commits this way, but now the reference points to a different commit so the other commits aren't part of this branch anymore.
This means that you just need to use the reference to get the "latest" commit of a branch which results in the following command:
git cherry-pick brA
On a sidenote: A workflow where you need to cherry-pick
every and each commit from one branch onto another seems kinda off to me and there is probably a better way to achieve whatever you want to do.
EDIT I have to correct myself: Of course branches in git aren't symbolic references but just usual references; the only type of symbolic references in git can be found in HEAD. HEAD usually points at a branch and not directly at a commit as branches do.
Upvotes: 2
Reputation: 5595
Other branches' commits can be referenced with the @
notation as follows:
git cp brA@{0}
They count backwards from the last commit and are zero-indexed. I have no idea how it would handle a commit with two parents, but for now, that's not my problem. That's 11 non-varying characters, "git cp " and "@{0}. This gives me a keystroke total of:
13 + 8 + 11 + commit message + branch name
Upvotes: 3