Search code examples
gitgit-rebase

git rebase [branch] AT entry point


I have in my current local branch 10 commits:

  • Commit 1 <<< oldest commit
  • Commit 2
  • ...
  • Commit 9
  • Commit 10 <<<< latest commit

I want to do git rebase other-branch but i dont want it to put it as the "oldest commit", meaning I dont want it to come in before "Commit 1".

I want to put it right before the latest commit, so after git rebase other-branch there will be

  • Commit 9
  • .......New commits here
  • Commit 10

I thought this would be possible, because we can use git rebase -i to move around commit order.


Solution

  • This will re-write the history of your branch, but you can accomplish this with:

    git reset --hard COMMIT9SHA
    git merge other-branch
    git cherry-pick COMMIT10SHA
    

    If you want to avoid a merge-commit, you could first switch to other-branch and rebase it off of COMMIT9SHA:

    git checkout other-branch
    git rebase COMMIT9SHA