Reputation: 1
Now there is a branch(branch1),
three people P1 P2 P3
they develop together on branch1
with the comimit log
P1 commit1
P2 commit2
P3 commit3
P3 commit4
P1 commit5
P2 commit6
...
P1 commit100
don't need to pay attention to the content of the submission records.
I just want to give an example of how they freely submit on this branch,
and there is a lot of commits
I want to create a new branch(branch2)
merge all code from branch1 into branch2
but each person will only have one commit,
such as
P1 commit1
P2 commit2
P3 commit3
May I ask if this is achievable? If possible, what should I do?
I don't know if these commands will work, such as
git cherry-pick
git rev-list
git filter-branch
git commit-tree
...
and complete interaction through scripts
Upvotes: 0
Views: 51
Reputation: 293
If you are looking for a single commit on the branch per person, using short-lived feature branches will let each user squash the commits on their own branch before merging to the trunk.
In the case of your existing branch
git rebase -i HEAD~6
When presented with the list of commits in the interactive editor:
pick 8aaaaaa CommitByPerson1
pick 7bbbbbb CommitByPerson2
pick 8cccccc CommitByPerson3
pick 7dddddd CommitByPerson1
pick 7eeeeee CommitByPerson2
pick 8ffffff CommitByPerson3
You can re-order them:
pick 8aaaaaa CommitByPerson1
pick 7dddddd CommitByPerson1
pick 7bbbbbb CommitByPerson2
pick 7eeeeee CommitByPerson2
pick 8cccccc CommitByPerson3
pick 8ffffff CommitByPerson3
And then squash them:
pick 8aaaaaa CommitByPerson1
squash 7dddddd CommitByPerson1
pick 7bbbbbb CommitByPerson2
squash 7eeeeee CommitByPerson2
pick 8cccccc CommitByPerson3
squash 8ffffff CommitByPerson3
You will be left with a single commit per-person.
Upvotes: 0