You can use a serial combination of git rebase
and git branch
to apply a group of commits onto another branch. As already posted by wolfc the first command actually copies the commits. However, the change is not visible until you add a branch name to the top most commit of the group.
Please open the picture in a new tab ...
![Workflow]()
To summarize the commands in text form:
- Open gitk as a independent process using the command:
gitk --all &
.
- Run
git rebase --onto a b f
.
- Press F5 in gitk. Nothing changes. But no
HEAD
is marked.
- Run
git branch selection
- Press F5 in gitk. The new branch with its commits appears.
This should clarify things:
- Commit
a
is the new root destination of the group.
- Commit
b
is the commit before the first commit of the group (exclusive).
- Commit
f
is the last commit of the group (inclusive).
Afterwards, you could use git checkout feature && git reset --hard b
to delete the commits c
till f
from the feature
branch.
In addition to this answer, I wrote a blog post which describes the commands in another scenario which should help to generally use it.