防止合并冲突的文件在git中提交 [英] prevent file with merge conflicts from getting committed in git

查看:163
本文介绍了防止合并冲突的文件在git中提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么方法可以防止合并冲突的文件在git中提交?没有人会故意提交有冲突的文件.但是有没有办法防止文件在git中提交?

Is there any way of preventing files with merge conflict from getting committed in git? No one is going to commit files with conflict intentionally. But is there a way to prevent files from getting committed in git?

git是否在任何地方都有任何设置或可配置值,可以通过查找<<<<<<<=======>>>>>>>符号来阻止文件?

Does git have any settings or configurable values anywhere, where it can prevent files by looking for <<<<<<<, ======= or >>>>>>> symbols?

推荐答案

VonC的答案已经说明了您可能希望在其中检查合并提交的各种钩子.

VonC's answer already explains the different kinds of hooks where you might want to check for merge commits.

如果您只是想要一个简单的解决方案来避免提交冲突,那么默认预提交钩子示例中的git中已经包含了该解决方案.只需通过将.git/hooks/pre-commit.sample重命名为.git/hooks/pre-commit来启用该挂钩.如果您随后尝试进行冲突:

If you just want a simple solution to avoid committing conflicts, that is already included with git in the default pre-commit hook sample. Just enable the hook by renaming .git/hooks/pre-commit.sample to .git/hooks/pre-commit. If you then try to commit a conflict:

$ git commit -am "Fix crash in frobnicate"
src/foo.c:239: leftover conflict marker

注意:

该脚本在内部使用git diff --check,它还会检查各种空白问题-因此您也可能会遇到空白错误.您也可以在确认发现问题之前运行git diff --check.有关详细信息和配置选项,请参见git diff的联机帮助页.

The script uses git diff --check internally, which also checks for various white space problems - so you might get whitespace errors as well. You can also run git diff --check before committing to find problems. See the manpage of git diff for details and config options.

这对git V2.0有效;不知道什么时候引入的.

This is valid for git V2.0; no idea when it was introduced.

这篇关于防止合并冲突的文件在git中提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆