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?
source to share
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 otherwisegit checkout private
)
1.bgit merge -s ours public
1.cgit checkout public
1.dgit 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 (otherwisegit checkout public
)
2.b willgit merge --no-commit private
prepare a merge-commit, but stop before taking any action if there is a merge conflict or not ... 2.cgit checkout -f private -- .
to check the current state of "private"
2.dgit add .
to mark conflicts as resolved (if any)
2.egit 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)
source to share