I want the following workflow for my project :
2 branches : dev and master (I make it simple for this question, but I actually also use features and release branches)
I commit technical changes on the dev branch.
When I want to release a new big version, I merge dev into master but without keeping the dev history. I don't want master branch to have any technical message like "Fixed bug in blablabla". I just want my master branch to show me the important release versions like this :
Initial commit ----- [PROD V1] ------ [PROD V2] ------
For that behavior, I use
git merge dev --squash -X theirs
on master branch to retrieve all changes that have been made in dev branch in the working directory of master, then create one single commit with the [PROD]
message and push.
The problem is that, after I tried the merge dev --squash -X theirs
on master branch, I noticed that some few files are baddly auto-merged (some entiere blocks of code are added twice..) which provoke eventually numerous errors in my PHP scripts.
As I understood, -X theirs take "theirs" (dev) version, but only when auto merging is not possible. The problem comes from auto merging (I saw that all files with that problem has been auto-merged).
How can I just disable auto-merging so all the files in the master branch are litterally replaced by the content of dev ?
I think I found the answer. git merge is meant to incorporate changes from a version of a file into another version. This is just not a replace tool.
-X theirs
just auto resolves a conflict by choosing their version, but at certain very particular lines (not whole file) where git doesn't know what to do. It's definitely not meant to replace the whole content of a file with "their" version, as I thought.
To replace the content of the file with "their" (dev) version, I did :
git merge dev --squash
Git says there are not resolved conflicts. Now to replace with their version for all files, I did :
git checkout --theirs *
And finally mark all conflict as resolved :
git add -u
Commit and push and it's all good :)