Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How move all commits from specific user to a new branch?

Tags:

git

branch

commit

I have 'commits' from many users. I want to move all commits of some user to a new branch.

How can i do this?

like image 496
HammerSpb Avatar asked Mar 29 '11 08:03

HammerSpb


People also ask

How do you create a new branch from a specific commit?

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.


1 Answers

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.

like image 187
Bombe Avatar answered Sep 22 '22 05:09

Bombe