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.
In a good workflow, the feature branch is deleted once its merged back into master. New branches should be created for each new feature(s) that you work on.
To merge branches locally, use git checkout to switch to the branch you want to merge into. This branch is typically the main branch. Next, use git merge and specify the name of the other branch to bring into this branch. This example merges the jeff/feature1 branch into the main branch.
Merging a branch multiple times into another works fine if there were changes to merge. Save this answer. Show activity on this post. Actually yes you totally can, when you merge again it will bring over any commits that don't exist on production.
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.
You can also --amend
the authorship afterwards if you already did the merge. like that:
git checkout master
git merge my_branch
git commit --amend --author="My Nick <[email protected]>"
git push origin master
This works as desired and adds the specified author to the merge commit. Simple as that.
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