I want to selectively promote a number of commits from one branch to another with a PR review.
Imagine I have on my master branch the following commits:
8b08096 - mod4 97eff67 - mod3 b64891f - mod2 fa6e804 - mod1 956e388 - initial On my staging branch I have only the following:
956e388 - initial I now want to "promote" the commits for mod1, mod2 & mod3 from master to the staging branch. So, from staging I create a new temporary branch and merge the commits up until mod3:
git checkout staging git checkout -b promote git merge 97eff67 Doing a git log now shows me all the commits including mod3 on my promote branch:
git log --pretty=oneline 97eff67 (HEAD -> promote) mod3 b64891f mod2 fa6e804 mod1 956e388 (origin/staging, staging) initial git push origin promote I can now create my PR for the team to review the changes.
However, when it comes to merging this into the staging branch, GitHub gives me 3 options; Merge, Squash & Merge and Rebase & Merge. I don't want to do Merge since that gives me a merge commit. I don't want to do Squash & Merge since that will squash all my commits into a single commit so I'm left with Rebase & Merge.
When I do a Rebase & Merge, all the changes are applied to the staging branch. However, all the commits have now been given new hashes (except of course for the "initial" commit):
2d7177a - mod3 2831f46 - mod2 a8a2e15 - mod1 956e388 - initial How can I merge the commits from my promote branch into my staging branch while keeping the commit hashes intact?
rebaseoption when the commit history allows a clean rebase. If you don't absolutely need the GH PR, you could rebase manually :/