Using a subtree-merge strategy, the story doesn't merge

I am trying to use an external SVN repository as a subtree in my repository by merging it with a subtree. I believe that this should keep the history of files in the library intact, but it does not work - files from the library that are combined into a subtree in my main branch have no history, and for fixing, when I add them, here is the history to show that I mean, exactly what I am going to get in this state follows.

lappy8086:YACYAML jamie$ git log --graph * commit 0cc6c4e5061741e67d009f3375ce1d2bcd3ab540 | Author: James Montgomerie | Date: Thu May 17 12:04:43 2012 +0100 | | Subtree-merge in libYAML (from a git-svn checkout). | * commit b5af5af109d77f6adafebc3dcf5a4796a5035a2e Author: James Montgomerie Date: Thu May 17 11:47:32 2012 +0100 First commit, add .gitignore. 

Here is what I am doing to try to get this to work:

 # check out SVN repo git svn clone http://svn.pyyaml.org/libyaml/branches/stable libYAML # create my repo mkdir YACYAML cd YACYAML git init touch .gitignore git add .gitignore git commit -m "First commit, add .gitignore" # Fetch from git-svn repo I got earlier git remote add libyaml-svn ../libYAML/ git fetch libyaml-svn git checkout -b libyaml-svn libyaml-svn/master # Switch back to master, and try to merge in subtree git checkout master git read-tree --prefix=libYAML/ -u libyaml-svn/master git commit -m "Merge in libYAML as subtree (from git-svn checkout of SVN repo)" 

This "works", but as I said when I look at my story, I expect to see the whole story from the libYAML repository, but I don’t ... it is as stated above.

+4
source share
2 answers

Well, one answer was to install git -subtree and use it for:

 git subtree add --prefix=libYAML/ ../libYAML master 

which leads to what I searched (and expected) from this manually:

 lappy8086:YACYAML jamie$ git log --graph * commit 453d464cfc140c798d0dea85ab667fe16250181d |\ Merge: 9fb083d 0ca365a | | Author: James Montgomerie | | Date: Thu May 17 14:32:36 2012 +0100 | | | | Add 'libYAML/' from commit '0ca365adeb5711bf918d4401e98fce00bab8b3ec' | | | | git-subtree-dir: libYAML | | git-subtree-mainline: 9fb083d923011dd990222da2a58eda42e5220cde | | git-subtree-split: 0ca365adeb5711bf918d4401e98fce00bab8b3ec | | | * commit 0ca365adeb5711bf918d4401e98fce00bab8b3ec | | Author: xi | | Date: Sun May 29 05:52:36 2011 +0000 | | | | Bumped the version number and updated the announcement. | | | | git-svn-id: http://svn.pyyaml.org/libyaml/branches/ stable@374 18f92427-320e-0410-9341-c67f048884a3 | | | * commit 210b313e5ab158f32d8f09db6a8df8cb9bd6a982 | | Author: xi | | Date: Sun May 29 05:29:39 2011 +0000 | | | | Added support for pkg-config. | | | | git-svn-id: http://svn.pyyaml.org/libyaml/branches/ stable@373 18f92427-320e-0410-9341-c67f048884a3 ...etc... 

I would still like to know the correct way to do this without git -subtree dependency though.

+2
source

There seems to be inconsistency in how git log [--follow] <filename> behaves when a merge involves repairing a tree inside a subdir, such as git subtree .

I did some experimentation, and if you introduce a synthetic reeducation of the source codeology right before the first subtree is merged, then the story will be reported through git log --follow <filename> .

The options I see are:

  • Fix git log to follow renames that happen during merge
  • Modify git subtree to create two commits for each add, re-parent tree in one commit first, and then merge re-commit after that
  • Set the problem manually by running # 2 with .git/info/grafts and git filter-branch

Workaround:

 $ git log --grep git-subtree-mainline commit 8789f3c80122d1fc52ff43ab776a7b186f51c3c6 Merge: 0c11300 4757376 Author: John Sumsion <email> Date: Wed Apr 17 09:43:21 2013 Add 'some-subdir/' from commit 'f54875a391499f910eeb8d6ff3e6b00f9778a8ab' git-subtree-dir: some-subdir git-subtree-mainline: 0c113003278e58d32116c8bd5a60f2c848b61bbb git-subtree-split: f54875a391499f910eeb8d6ff3e6b00f9778a8ab $ git checkout -b fix Switched to a new branch 'fix' $ mkdir -p some-subdir $ git mv <files> some-subdir $ git commit -m "Re-parenting files before subtree merge to preserve 'git log --follow' history" $ echo <orig_merge> <orig_parent> <fixed_merge_parent> >> .git/info/grafts $ git filter-branch --index-filter true --tag-name-filter cat master 

Where are the following commits:

  • orig_merge : 8789f3c80122d1fc52ff43ab776a7b186f51c3c6
  • orig_parent : 0c113003278e58d32116c8bd5a60f2c848b61bbb
  • fixed_merge_parent : sha from git commit

Unfortunately, subsequent changes git subtree via git subtree after the first merge of the subtree do NOT appear with the message via git log --follow <filename> , even if the merge of the first subtree is synthetically redirected.

For some reason, I seem to remember that this worked fine in the Git 1.7.x timeframe, but it is vague memory from the distant past that I don't have time to research. Git 1.8.3.2 was noted above.

+2
source

Source: https://habr.com/ru/post/1412966/


All Articles