Git merge: take everything from the "them" branch

I have two branches, "private" and "public". I am working on a private and periodically, I want to replace everything in the "public" branch to have a clean copy of the files in "private".

Since I don't want the "private" history to go to "public", I use git merge --squash

, but I still manually resolve the merge files one by one. Is there a better way to do this?

+3


source to share


2 answers


I think,

git merge -X theirs private

      



is what you are looking for. And of course you can add --squash

as you like.

+5


source


Compressing the merge will not change the fact that there are conflicts if the same lines were changed in both commit files.

To drop the entire "public" branch entirely and take the exact state of the "public", you can do one of the following:

  • Use a merge strategy ours

    (not a variant of the strategy) as indicated in several other commits:
    1. Suppose you are on the "private" branch (do otherwise 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 now point to a merge commit; if you want "private" to point to a commit before the merge, do :) git checkout private; git reset --hard private@{1}

    (Note that this uses a reflog and will only work like this: unless you changed "private" in the meantime)

  • Check "your" side manually:
    2.a suppose you are on the "public" branch (otherwise git checkout public

    )
    2.b will git merge --no-commit private

    prepare a merge-commit, but stop before taking any action if there is a merge conflict or not ... 2.c git checkout -f private -- .

    to check 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 same content as "private"



Edit: Note that this is an inverted case How do I rewrite ', not' merge ', a branch to a different branch in Git?

Edit 2: If you want to hide your single public announcements you can also use the switch --squash

here (of course (in steps 1.b and 2.b)

+1


source







All Articles