Re: Branches merging by only overwrite files
- From
Junio C Hamano <junkio@cox.net>
- Date
- Dec 11, 2005, 09:33 UTC
- Message-ID
- <7vbqzonfkx.fsf@assigned-by-dhcp.cox.net>
- In-Reply-To
- <439BE3B9.3040308@ust.hk>
Ben Lau <benlau@ust.hk> writes:
> I am looking for a solution to merge two branches but do not perform > file level merge. Instead, I wish the result file is the copy from any > one of the branches.
It might be better to state why you need this first. It could be that what you really want to solve is not related to merge at all.
Show 5 quoted lines
> For example, assumes it has two branches A and B, some of the files > are modified in both of them. In this case, `/usr/bin/merge` could not > be execated, it just have to choose the revision from branch A and > discards all the changes from B. For the rest of files, it just simply > choose the newest copy from A or B.
I wonder why you say "could not be executed". I take it to mean you just do not want to even when it could.
Now, it is not clear if you always want copy from branch A and not from branch B when both branches have the same path, or you want to pick one at random between A and B. If branch A kept the file intact and branch B modified it, what do you want to happen? The default "merge" semantics in git (unless you are using "ours" strategy) in such a case is always to take the version from branch B. Is that consistent with what you want?
What do you exactly mean "newest copy from A or B"? What are you basing the "newest" determination on? The commit date of A and B commits, or the author date ot two?
Assuming that you can give reasonable and consistent answer to the above question to define the semantics of your "new merge algorithm", what you would do is to write a new script git-merge-benlau to implement whatever semantics you picked. You could model it after existing merge strategy, such as git-merge-resolve.sh or git-merge-stupid.sh. Then you give the new merge strategy to "git-merge" or "git-pull".
For example, if you want all the usual "trivial merges" to work just like the default git merge algorithms, but always take "our" version instead of running file-level merge when both sides modified a file, then you start from a copy of git-merge-stupid.sh, and replace "git-merge-one-file" with "git-merge-one-file-benlau'. Copy "git-merge-one-file.sh" to create another new script, "git-merge-one-file-benlau", and replace this line:
merge "$src1" "$orig" "$src"
with
cat "$orig" >"$src1"
and you are done.
I outlined the above without knowing what you really want to achieve, and I do not think the resulting merge strategy makes much sense, but that is what I get form hacking without knowing what you are really trying to do ;-).