Squashing the merge will not change the fact that there are conflicts if the same lines have changed on both files of the commit.
To completely discard everything on the "public" branch and take over the exact state of "public", you can do one of these:
Use the ours
merge strategy (not the strategy option) as pointed out in several other commits:
1.a assume you are on branch "private" (otherwise, do git checkout private
)
1.b git merge -s ours public
1.c git checkout public
1.d git merge --ff-only private
1.e (optional: both branches are now pointing to the merge commit; if you want "private" to point to the commit before the merge, do:) git checkout private; git reset --hard private@{1}
(Note that this uses the reflog and will only work like this if you havent changed "private" in the meantime)
Check out the "theirs" side manually:
2.a assume you are on branch "public" (otherwise, git checkout public
)
2.b git merge --no-commit private
will prepare a merge-commit, but stop before committing no matter if there is a merge conflict or not
2.c git checkout -f private -- .
to check out the current state of "private"
2.d git add .
to mark conflicts as resolved (if any)
2.e git commit
to save the merge commit; "public" will now have the exact same contents as "private"
Edit: Note that this is the inverted case of How do I 'overwrite', rather than 'merge', a branch on another branch in Git?
Edit 2: If you want to hide your single commits of public, you can use the --squash
switch here too, of course (in steps 1.b and 2.b, respectively)