GIT squash per users
All the examples I've seen deal with branches where there is only one committer. What I am trying to achieve is an automatic git rebase -i
where, for a given branch.. all commit made by a given user will be squashed together.
hence, if 3 people work on a branch.. when the branch is merg开发者_高级运维ed with master, we would see only 3 commits in the history.. one per user. Kind of a rebase + squash together with a twist of user.
Hope I made myself clear.. ;-/
Any pointers would help,
Sincerely,
I'm going to try to convince you that you simply do not do this for four reasons:
- You are throwing away history.
- History on the server will diverge from all of the committers' history, because you are doing the rebase post-push. All committers will have to deal with the hassle of non-fastforward merges of the shared master each time you do this.
- You are almost-surely creating non-atomic commits by combining multiple commits into one, a corollary of "don't throw out history." The point of atomic commits is to make history comprehensible, to easily identify the cause of regressions, and even to make code reuse possible through cherry-picks (and probably other good reasons I can't think of off the top of my head).
- You can alter changes and end up with a final product that is not the sum of each user's commits, as I mentioned in my comment. Consider cases of committers A and B that modify the same files (especially the same content in the same files) when their contributions are interleaved like A, B, A A and you squash to AAA, B or B, AAA (where AAA is the squash result). This will bite you hard.
I would not suggest doing that as you would throw away history. Also the users that do the rebase should be doing this not you on the central repository as you are going to get into diverging histories if the server modifies stuff the clients still have.
As for the rebasing you could try to hack something together like this (not actually working but may help out)
# assuming you are on master
git -i rebase origin/master
//find out what file is opened by git when doing the interactive rebase
regex search & replace pick with squash
close file .. somehow continue git process (kill -9 the text editor maybe?)
By reading the manpage I could not find any way to merge everything.. You could go deeper and mess with the git internal commands.. but that's beyond my knowledge..
精彩评论