avoid auto merging of git conflicts and warn if same files getting modified in different branches

扶醉桌前 提交于 2021-01-29 09:12:16

问题


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.

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

AAA
BBB

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

AAA
BBB
CCC

also added new file Test2.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.

Please assist how to achieve.

回答1:


It seems like your intent is to have all the code reviewed before merging into master. This is typically achieved through the pull request feature in Github/Bitbucket or the merge request feature in Gitlab. Is this what you're looking for?




回答2:


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]* //'

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



来源:https://stackoverflow.com/questions/62638966/avoid-auto-merging-of-git-conflicts-and-warn-if-same-files-getting-modified-in-d

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!