问题
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
AAABBB
Feature branch (feature/test1) created out of master and updated file test1.txt
AAABBB
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