All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eduard Egorov <Eduard.Egorov@icl-services.com>
To: 'Jeff King' <peff@peff.net>,
	"'paul@mad-scientist.net'" <paul@mad-scientist.net>
Cc: "'git@vger.kernel.org'" <git@vger.kernel.org>
Subject: RE: git merge deletes my changes
Date: Tue, 11 Oct 2016 07:11:19 +0000	[thread overview]
Message-ID: <AM4PR03MB163637D73077F3DDEDCF21A9DBDA0@AM4PR03MB1636.eurprd03.prod.outlook.com> (raw)
In-Reply-To: <20161010152626.frc3ypflwnhzidea@sigill.intra.peff.net>

Hello Jeff, Paul

Thanks a lot for sharing your time!

As you correctly stated, I used  "--squash" for preventing my project history being flooded with the ceph_ansible's commits and  I didn't really understand that this is critical for having relationship history with other repository.

Also I realized that made another big mistake - I should use another branch (that is directly branched from 'ceph-ansible' one) for storing my ceph-ansible's code updates. And, periodically, this branch will be merged into my main repo with '-s subtree --squash' without worrying about merge conflicts since this folder would never be changed in main repo's branches.

Again - thank you very much for your help!

P.S. Please feel free to copy-paste this thread as an answer on SO (http://stackoverflow.com/questions/39954265/git-merge-s-subtree-works-incorrectly ) - I will accept it with great pleasure ;-)

With best regards
Eduard Egorov

-----Original Message-----
From: Paul Smith [mailto:paul@mad-scientist.net] 
Sent: Monday, October 10, 2016 8:52 PM
To: Eduard Egorov <Eduard.Egorov@icl-services.com>; 'git@vger.kernel.org' <git@vger.kernel.org>
Subject: Re: git merge deletes my changes

On Mon, 2016-10-10 at 10:19 +0000, Eduard Egorov wrote:
> # ~/gitbuild/git-2.10.1/git merge -s subtree --squash ceph_ansible
> 
> Can somebody confirm this please? Doesn't "merge -s subtree" really 
> merges branches?

I think possibly you're not fully understanding what the --squash flag does... that's what's causing your issue here, not the "-s" option.

A squash merge takes the commits that would be merged from the origin branch and squashes them into a single patch and applies them to the current branch as a new commit... but this new commit is not a merge commit (that is, when you look at it with "git show" etc. the commit will have only one parent, not two--or more--parents like a normal merge commit).

Basically, it's syntactic sugar for a diff plus patch operation plus some Git goodness wrapped around it to make it easier to use.

But ultimately once you're done, Git has no idea that this new commit has any relationship whatsoever to the origin branch.  So the next time you merge, Git doesn't know that there was a previous merge and it will try to merge everything from scratch rather than starting at the previous common merge point.

So either you'll have to use a normal, non-squash merge, or else you'll have to tell Git by hand what the previous common merge point was (as Jeff King's excellent email suggests).  Or else, you'll have to live with this behavior.

-----Original Message-----
From: Jeff King [mailto:peff@peff.net] 
Sent: Monday, October 10, 2016 6:26 PM
To: Eduard Egorov <Eduard.Egorov@icl-services.com>
Cc: 'git@vger.kernel.org' <git@vger.kernel.org>
Subject: Re: git merge deletes my changes

On Mon, Oct 10, 2016 at 09:39:13AM +0000, Eduard Egorov wrote:

> A week ago, I've reset a state of 'ceph-ansible' folder in %current% 
> branch with code from corresponding branch (that tracks an upstream 
> from github):
> 
> # git read-tree --prefix=ceph-ansible/ -u ceph_ansible

This pulls in the subtree files, but there's no actual relationship with the commit history in ceph_ansible.

So later...

> Then I've committed several changes, including:
> 
> 1. Renamed file and commited:
> # git mv site.yml.sample site.yml
> 
> 2. Made some changes and committed
> 
> 3. Pulled updates from original branch by:
> # git merge -s subtree --squash ceph_ansible
> 
> It said:
>     Auto-merging ceph-ansible/site.yml.sample
>     blablabla
>     Squash commit -- not updating HEAD
>     Automatic merge went well; stopped before committing as requested

When you merge from ceph_ansible, there is no shared history, and git uses the empty tree as a common ancestor. It looks like the other side added site.yml.sample, for instance, because that is a change from the empty tree.

> A post on SO: 
> http://stackoverflow.com/questions/39954265/git-merge-deletes-my-chang
> es

As you noted on SO, modern git disallows merges of unrelated history by default, because it's usually a mistake to do so.

If you are doing repeated merges into the subtree, you need to somehow tell git how the histories are related. The obvious answer is to do a "git merge -s ours ceph_ansible" after your initial read-tree, so that git knows you've pulled in the changes up to that point. But I'd guess from your use of "--squash" that you don't want to carry the ceph_ansible history in your project.

So you need to record the original upstream commit somewhere (probably in the commit message when you commit the read-tree result), and then ask git to use that as the merge-base during subsequent merges (which will require using plumbing codes, as git-merge wants to compute the merge base itself).  I believe the git-subtree command (in contrib/subtree of git.git) handles this use case, but I haven't used it myself.

-Peff

  reply	other threads:[~2016-10-11  7:45 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-10  9:39 git merge deletes my changes Eduard Egorov
2016-10-10 15:26 ` Jeff King
2016-10-11  7:11   ` Eduard Egorov [this message]
     [not found] <AM4PR03MB1636BE3423E2BC4F0E998159DBDB0@AM4PR03MB1636.eurprd03.prod.outlook.com>
2016-10-10 10:19 ` Eduard Egorov
2016-10-10 17:52   ` Paul Smith
2016-10-11 15:56     ` Jakub Narębski
2016-10-12  5:51       ` Eduard Egorov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=AM4PR03MB163637D73077F3DDEDCF21A9DBDA0@AM4PR03MB1636.eurprd03.prod.outlook.com \
    --to=eduard.egorov@icl-services.com \
    --cc=git@vger.kernel.org \
    --cc=paul@mad-scientist.net \
    --cc=peff@peff.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.