简体   繁体   中英

GIT - Force manual merge for branch that would otherwise merge cleanly

I have the following situation

git branch
* master

git branch upgrade-project
git checkout upgrade-project

# At this point I run an update script from a third party that replaces 
# many files I have already modified.
git checkout master

# I want all conflicts to be marked regardless of weather GIT can merge them automatically.
git merge upgrade-project    

The problem there is that it will cleanly merge all files replaced by the update-scripts from the upgrade-project branch as it is ahead of master which makes perfect sense in normal situations.

What I want is that when I merge upgrade-project into master all files that are in conflict are marked as such.

This was I can manually compare and make my modifications as needed.

Is this possible?

Merge your branch, but do not commit the changes:

git merge --no-commit upgrade-project

Clean the index, leaving the changes in working directory:

git reset

Resolve any conflict marked with <<<<< if any.

Interactivelly add the "good" changes you need to the index and commit them:

git add -p
git commit

Clean your working directory from unnecessary changes:

git reset --hard

upgrade-project branch is ahead of master .
Merging upgrade-project back into master would merge cleanly (no conflicts).
I would like to force conflicts for all files that are not exactly the same

You can get a list of the files which are going to be pulled out before you execute the pull:

git checkout master
git diff --name-only upgrade-project

or:

git log --stat master ^upgrade-project

or

git format-patch master...upgrade-project 

The last code sample will create a patch of each commit you have (diffrence between the branches which are going to be merged).

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