I have 'commits' from many users. I want to move all commits of some user to a new branch.
How can i do this?
In order to create a Git branch from a commit, use the “git checkout” command with the “-b” option and specify the branch name as well as the commit to create your branch from. Alternatively, you can use the “git branch” command with the branch name and the commit SHA for the new branch.
Find all commits by one author and save their hash to a file:
git log --author=<author> --format=%H > /tmp/commit-by-x
Create a new branch that does not contain this particular's author commit since you don't want to apply them twice. For this, you can create a new empty branch:
git checkout --orphan commits-by-x
Cherry-pick all commits of that author (from oldest to newest):
tac /tmp/commit-by-x | while read sha; do git cherry-pick ${sha}; done
Obviously, if you want this to succeed the changes introduced by author-x have to be very localized.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With