tags:

views:

37

answers:

2

let's say that my colleage John has created a branch called 'john'. It has 10 committs by John. When it comes to merging back to master they ask me to do merging.

This is what I do

git checkout -b john origin/john
git rebase master
git checkout master
git merge john --squashed
git add .
git commit -m 'merged branch john'

However now what happens is that it is my id against the merged commit. And later people come asking me why did I change certain part of code.

How do I collapse all the comitts in john branch into one commit such that John is the author. I guess git commit interactive can help but could not quite understand.

+1  A: 

The issue here is that git merge --squash will apply the same changes as a normal merge, but without retaining the merge information. Then, when you commit, it's the same as any commit you make: it's attributed to you. You could change the commit's author information using git commit --author="Original Author <email@server>". See git-commit(1) for more information on the --author switch.

But the question I have is: why are you squashing the merge? Why not just do a non-squashed merge? If anyone does a git blame, it will be appropriately attributed to the commit by the original author.

Joseph Spiros
so that I could easily roll back since after squashed it is one single commit that needs to be rolled back. If I don't squash then it will be 10 comitts to rollback unless there is a better way.
Nadal
As noted in mfontani's answer, if you merge --no-ff, a merge commit will be recorded, and if you rollback that one commit, it'll have the same effect as rolling back a squashed commit, but with the added benefit of recording the complete commit history as well.
Joseph Spiros
+1  A: 

If you do the following:

git checkout -b john origin/john
git rebase master
git checkout master
git merge --no-ff john # forces a merge commit to be recorded

you'll be able to both both retain the authorship of John's commits and be able to revert the merge by reverting the SHA of the merge commit.

mfontani
really that's awesome. I guess I should do some testing myself if I commit using git merge --no-ff john then will I get to see 10 committs in my master log from john or will I see one commit as I would see in case of squashed. I don't mind 10 comitts lin the log. my only concern was that I should be able to revert easily.
Nadal
You will see all the commits you rebased, but you will be able to undo the merge just by reverting the merge commit.Furthermore, you keep track of which commits belonged to which branch :)
mfontani
I look forward to hearing whether the above worked out for you, and therefore answers your original question.
mfontani