简体   繁体   中英

git merge: is there a way to force --squash?

So, the dev workflow for our project is like this: we create a task/bug ticket, and we branch off master to work on the task/bug, and eventually merge it back to master. We would like the commits on master to have nice messages. People committing on the task branch may not have good commit messages, and that's ok, but if the branch is to be merged, these commits with unclean messages are going into master.

One way to solve this is to always merge to master with --squash. That way, you get a chance to supply good commit message and treat the whole range of commits as one. I'm wondering if there's a way to enforce that? meaning, if we can let git server reject merges that aren't squashed?

While it's not directly forcing, you could set --squash as default merge option for the master branch:

git config branch.master.mergeoptions  "--squash"

This will always squash the commits being merged into master without having to specify the --squash option.

You need is a server side hook to ensure that what is getting pushed is what you need. You would reject any reference change that would introduce more than one non-merge commit. You could do other checks there like seeing that the comment contains a ticket number, etc.

你可以在你的分支上使用rebase -i ,这将允许你基本上将分支上的所有提交压缩为1次提交,然后将该分支(1次提交)合并到master。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM