避免自动合并git冲突,并警告如果在不同分支中修改了相同文件 [英] avoid auto merging of git conflicts and warn if same files getting modified in different branches

查看:219
本文介绍了避免自动合并git冲突,并警告如果在不同分支中修改了相同文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通常,当我们将要素分支与master或任何其他分支合并时,如果在不同分支中但在不同行上修改了相同文件,则GIT会自动解决冲突.我们不希望这些合并自动发生,并且希望GIT会警告我们两个要合并的分支中已修改的公用文件列表.

Usually when we merge feature branch with master or any other branch and if same file is modified in different branches but on different lines then GIT does resolve the conflict automatically. We dont want these merge happened automatically and expecting GIT should warn us with list of common files modified in two branches to be merged.

例如在Master中,我们有以下文件test1.txt

e.g. In Master, we have file test1.txt as below

从主文件创建功能分支(功能/test1)并更新文件test1.txt

Feature branch (feature/test1) created out of master and updated file test1.txt

还添加了新文件Test2.txt

also added new file Test2.txt

如果我在master中合并功能分支,则它将自动解决冲突并成功合并文件内容.我们希望如果在功能和master分支中修改了相同的文件,则不应进行自动合并,甚至应警告说test1.txt已修改,需要手动合并.

If I merge feature branch in master then this is will resolve conflicts automatically and merges the file contents successfully. We wanted if same file is modified in feature and master branch then automatic merge should not occur, howeven it should warn saying test1.txt is modified and needs manual merge.

推荐答案

不是自动化的解决方案,但是您可以按如下方式获得两个分支中修改的文件列表:

Not an automated solution, but you can get the list of files modified in both branches as follows:

(git log --format="" --name-only branch1..branch2 | sort -u
 git log --format="" --name-only branch2..branch1 | sort -u) |
sort |
uniq -c |
sed '/  *1 /d; s/  *[0-9][0-9]* //'

已更新,以确保每个 git log 命令中每个文件仅代表一次.

updated to ensure that each file is represented only once in each git log command.

这篇关于避免自动合并git冲突,并警告如果在不同分支中修改了相同文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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