Use
git cherry-pick <commit>
to apply <commit> to your current branch.
I myself would probably cross-check the commits I pick in gitk and cherry-pick them with right-clicks on the commit entry there instead.
If you want to go more automatic (with all its dangers) and assuming all commits since yesterday happened on wss you could generate the list of commits using git log (with --pretty suggested by Jefromi)
git log --reverse --since=yesterday --pretty=%H
so everything together assuming you use bash
for commit in $(git log --reverse --since=yesterday --pretty=%H);
do
git cherry-pick $commit
done
If something goes wrong here (there is a lot of potential) you are in trouble since this works on the live checkout, so either do manual cherry-picks or use rebase like suggested by Jefromi.
Answer from Benjamin Bannier on Stack OverflowUse
git cherry-pick <commit>
to apply <commit> to your current branch.
I myself would probably cross-check the commits I pick in gitk and cherry-pick them with right-clicks on the commit entry there instead.
If you want to go more automatic (with all its dangers) and assuming all commits since yesterday happened on wss you could generate the list of commits using git log (with --pretty suggested by Jefromi)
git log --reverse --since=yesterday --pretty=%H
so everything together assuming you use bash
for commit in $(git log --reverse --since=yesterday --pretty=%H);
do
git cherry-pick $commit
done
If something goes wrong here (there is a lot of potential) you are in trouble since this works on the live checkout, so either do manual cherry-picks or use rebase like suggested by Jefromi.
You should really have a workflow that lets you do this all by merging:
- x - x - x (v2) - x - x - x (v2.1)
\
x - x - x (wss)
So all you have to do is git checkout v2.1 and git merge wss. If for some reason you really can't do this, and you can't use git rebase to move your wss branch to the right place, the command to grab a single commit from somewhere and apply it elsewhere is git cherry-pick. Just check out the branch you want to apply it on, and run git cherry-pick <SHA of commit to cherry-pick>.
Some of the ways rebase might save you:
If your history looks like this:
- x - x - x (v2) - x - x - x (v2.1)
\
x - x - x (v2-only) - x - x - x (wss)
You could use git rebase --onto v2 v2-only wss to move wss directly onto v2:
- x - x - x (v2) - x - x - x (v2.1)
|\
| x - x - x (v2-only)
\
x - x - x (wss)
Then you can merge! If you really, really, really can't get to the point where you can merge, you can still use rebase to effectively do several cherry-picks at once:
# wss-starting-point is the SHA1/branch immediately before the first commit to rebase
git branch wss-to-rebase wss
git rebase --onto v2.1 wss-starting-point wss-to-rebase
git checkout v2.1
git merge wss-to-rebase
Note: the reason that it takes some extra work in order to do this is that it's creating duplicate commits in your repository. This isn't really a good thing - the whole point of easy branching and merging is to be able to do everything by making commit(s) one place and merging them into wherever they're needed. Duplicate commits mean an intent never to merge those two branches (if you decide you want to later, you'll get conflicts).
git - How to cherry pick from 1 branch to another - Stack Overflow
How can I replicate the MR cherry-pick function from the UI using the cli tool?
How to properly move a commit from one branch to another now, if the two branches will be merged later?
i think you can do git reset soft head 1, then stash your changes then checkout the other branch, stash apply, then do the commit there
More on reddit.comIs there an easy way to apply a commit from one branch to a different branch?
What does git cherry-pick do?
Does git cherry-pick move or copy a commit?
Can you cherry-pick multiple commits at once?
When you cherry-pick, it creates a new commit with a new SHA. If you do:
git cherry-pick -x <sha>
then at least you'll get the commit message from the original commit appended to your new commit, along with the original SHA, which is very useful for tracking cherry-picks.
If you're an IntelliJ user, it's pretty simple.
Here, I am cherry-picking a commit from master branch to give-me-commit-branch. Note a few points in the below pic:
- destination: The current checkout branch is
give-me-a-commit-branch. Denoted by tag icon. - source: The selected
masterbranch whose commit logs are displayed on the right side is the source of the commit. - searching ability: Using the search (lens icon) option, we can find the revision number.
- multiple-selections: At a time, we can select multiple commits and cherry-pick them at one go!
This is easy-to-use and transparent.
