Search code examples
gitgit-rebase

how can I rebase a range of changes into another branch with just one commit?


I have the branches like below:

             L--M   <-- master
            /
...--A--B--C
            \
             D--E--F--G--H-I--J--K   <-- dev(HEAD)

What I want to do is to copy the EFGHIJ to master with one commit, like below:

             L--M--N   <-- master
            /
...--A--B--C
            \
             D--E--F--G--H-I--J--K   <-- dev(HEAD)

The N should contain EFGHIJ changes.

I can use the rebase --onto command to rebase the changes to master

git rebase --onto master E~1 J

If I use git push, there would exist the EFGHIJ changes in master. Maybe I need use git rebase -i command to change them into one, but, the question is, I cannot see the change history the previous changes applied by git rebase --onto!

How can I commit them with just one commit?


Solution

  • After git rebase --onto master E~1 J run

    git reset --soft M
    git commit -m 'changes from E F G H I and J'
    

    Done!