gitrebasing

Rebase a single commit to HEAD


I would like to rebase a given commit to be HEAD of my current branch. Of course I can use git rebase -i <future-head-SHA>~ and then move it down to HEAD (as described in this question), but I want to automate this process.

Is there a neat way to do this?

Thanks


Solution

  • Not really. Interactive rebase is the only tool designed to do this kind of thing. You could, hypothetically, script this, though:

    The following should work, provided you have GNU sed installed (other editions of sed usually don't support the -i flag):

    GIT_SEQUENCE_EDITOR="sed -i -e '1 {h; d}; $ {p; g}'" git rebase -i <commit>~