Created
December 14, 2017 13:20
-
-
Save TiddoLangerak/a4b2a5bbaa26aca4ca4fad6949a00edd to your computer and use it in GitHub Desktop.
git onto
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Suppose you've branched from master like this: | |
``` | |
master: a --- b --- c | |
\ | |
feature: d - e | |
\ | |
feature-patch: f - g | |
````` | |
Traditional wisdom says to not touch the `feature` branch now, since that would make it difficult to rebase `feature-patch` onto `feature`. | |
However, `git` got you covered! | |
Suppose `master` now introduces commit `x`, and you rebase `feature` onto `master. Your git tree then looks like this: | |
``` | |
master: a --- b --- c --- x | |
| \ | |
feature: \ d' - e' | |
\ | |
feature-patch: d - e - f - g | |
``` | |
`d'` and `e'` are now the same commits as `d` and `e`, but then rebased onto master. As you know, when you now try to rebase `feature-patch` onto `feature` then you're in a world of pain, as git doesn't see that `d == d'` and thus you get conflicts all over the place. | |
But there's a simple trick to skip this: | |
``` | |
git rebase --onto feature e | |
``` | |
You now tell git to rebase everything onto `feature` that has changed since `e`, which is only commit `f & g`. Git will then simply drop commits `d` `e`, and only try to rebase `f & g` onto `feature`, which should go without much problems: | |
``` | |
master: a --- b --- c --- x | |
\ | |
feature: d' - e' | |
\ | |
feature-patch: f - g | |
``` | |
So it's basically a way of saying "checkout feature, and then cherry pick f & g onto it". |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment