Search code examples
gitgit-rebase

git rebase -i for specific commits?


I have a branch with a few commits I'd like to interactively rebase. However, after pulling and merging there are now other commits interleaved with mine so I can't just do something like git rebase -i HEAD~3

Is it possible to do an interactive rebase while choosing individual commits? Something like git rebase -i 23duirs 3eujsfe ...

Another possibility-- If I simply run git rebase -i I believe it's possible to cut and paste my commit lines to be consecutive, and squash from there, is that correct? Is there a best practice for doing so, to minimize the chance of conflicts with the unrelated commits in there?


Solution

  • Given this

    pick <unrelated a>
    pick A
    pick <unrelated b>
    pick B
    pick <unrelated c>
    

    you can definitely do

    pick <unrelated a>
    pick <unrelated b>
    pick <unrelated c>
    pick A
    squash B
    

    Provided that your commit are really unrelated to the other changes, this will work just fine.