From owner-freebsd-git@freebsd.org Wed Dec 23 15:39:41 2020 Return-Path: Delivered-To: freebsd-git@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id AEFEB4C2B77 for ; Wed, 23 Dec 2020 15:39:41 +0000 (UTC) (envelope-from uqs@freebsd.org) Received: from acme.spoerlein.net (acme.spoerlein.net [IPv6:2a05:fc87:1:5::15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "www.spoerlein.net", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4D1HSs1dvZz3JvX; Wed, 23 Dec 2020 15:39:40 +0000 (UTC) (envelope-from uqs@freebsd.org) Received: from localhost (acme.spoerlein.net [IPv6:2a05:fc87:1:5:0:0:0:15]) by acme.spoerlein.net (8.16.1/8.15.2) with ESMTPS id 0BNFdd1u002504 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Wed, 23 Dec 2020 16:39:39 +0100 (CET) (envelope-from uqs@freebsd.org) Date: Wed, 23 Dec 2020 16:39:39 +0100 From: Ulrich =?utf-8?B?U3DDtnJsZWlu?= To: Renato Botelho Cc: Shawn Webb , freebsd-git@freebsd.org Subject: Re: Migrating a merge based project to new tree Message-ID: References: <20201223141517.xk66q3fboch6fwhj@mutt-hbsd> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: User-Agent: Mutt/2.0.1 (2020-11-14) X-Rspamd-Queue-Id: 4D1HSs1dvZz3JvX X-Spamd-Bar: / Authentication-Results: mx1.freebsd.org; none X-Spamd-Result: default: False [0.00 / 15.00]; ASN(0.00)[asn:39540, ipnet:2a05:fc87::/32, country:CH]; local_wl_from(0.00)[freebsd.org] X-BeenThere: freebsd-git@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Discussion of git use in the FreeBSD project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 23 Dec 2020 15:39:41 -0000 On Wed, 2020-12-23 at 11:29:10 -0300, Renato Botelho wrote: >On 23/12/20 11:15, Shawn Webb wrote: >> On Wed, Dec 23, 2020 at 09:35:11AM -0300, Renato Botelho wrote: >>> I'm working to migrate a downstream stable/12 based tree to the new git >>> repository following instructions from [1]. >>> >>> I did a final merge from legacy repository and made sure top commits on both >>> branches point to the same tree: >>> >>> # git show -s --format=%T f4d0bc6aa6b9 >>> 98db7229803a5c93e3132bc661201f204487eee9 >>> # git show -s --format=%T f262e04c92d7 >>> 98db7229803a5c93e3132bc661201f204487eee9 >>> >>> When I try to merge new one git refuses to merge due to unrelated histories. >>> Should I use --allow-unrelated-histories parameter? >>> >>> [1] https://github.com/freebsd/git_conv/wiki/Migrating-merge-based-project-from-legacy-git-tree >> >> HardenedBSD's in the same boat. We're toying around with different >> methods of fixing our repo right now. When I used >> --allow-unrelated-histories, git noted merge conflicts on every single >> file HardenedBSD has touched over the last 7.5 years. I tacked on "-X >> ours" and that made git happy. However, I'm unsure git always did the >> right thing. I'm working to verify that this week along with trying >> the other documented methods. > >I've managed to do it adding `-s ours` to change merge strategy and >preserve our changes. > >git merge legacy/stable/12 >git push origin devel-12 >git merge --allow-unrelated-histories -s ours freebsd/stable/12 > >After that I can confirm there are no differences: > ># git status >On branch devel-12 >Your branch is ahead of 'origin/devel-12' by 243035 commits. > (use "git push" to publish your local commits) > ># git diff origin/devel-12 ># Heh, you can simply write out your own commit and give it a number of parents (any number you like). Given your example above, you can merge those two commits (with the same tree, or with a tree from your actual branch) like so: tree=98db7229803a5c93e3132bc661201f204487eee9 git commit-tree -m "now kiss" -p f4d0bc6aa6b9 -p f262e04c92d7 98db7229803a5c93e3132bc661201f204487eee9 This will spit out a new commit hash, that has the tree of your choosing as well as those 2 commits as parents. You still need to stick that ref into something that you can name. Now I never know what git reset does precisely, but I think you can point your checkout out copy to that commit with git reset --hard or you stick it into a brand new ref (also called a branch). git update-ref refs/heads/my_merge If you can easily rebase your changes, that would be best. If the changes are scattered throughout the history and upstream was frequently merged, that doesn't work of course. If you don't need the per-change history, you can of course extract a patch and apply it to a clean tree, but that seems a lot of effort when you can craft your own commits with a one liner and then just need to update a ref to point to it (somehow). hth Uli