Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git log shows very little after doing a read-tree merge

Tags:

git

So I have done a merge of another repository into a subdirectory of the current repository, as:

git remote add -f Bproject /path/to/B
git merge -s ours --no-commit Bproject/master
git read-tree --prefix=dir-B/ -u Bproject/master
git commit -m "Merge B project as our subdirectory"

There seem to be subtle problems, though. When I do

git log dir-B/

the result is just the "Merge B project as our subdirectory" message. How do I get the log information I want, that is, the imported history of dir-B?

like image 302
U2EF1 Avatar asked Nov 16 '25 16:11

U2EF1


1 Answers

Your merge commit shows example.txt in BProject/master as being renamed to dir-B/example.txt. git log doesn't follow the history of a file/directory past renaming unless the --follow option was used:

--follow
Continue listing the history of a file beyond renames (works only for a single file).

If you are really desperate to get the diffs showing correctly, you can rewrite the Bproject/master history as though the project has always been in a directory dir-B, then do an ordinary merge. This will mean the SHAs of the merged history bear no relation to the ones on Bproject/master! The timestamp, author and commit message will all retain their original values though.

If you want to do this, I would suggest cloning Bproject seperately first, then running this in that clone:

git-filter-branch manpage

To move the whole tree into a subdirectory, or remove it from there:
git filter-branch --index-filter \
        'git ls-files -s | sed "s-\t\"*-&newsubdir/-" |
                GIT_INDEX_FILE=$GIT_INDEX_FILE.new \
                        git update-index --index-info &&
         mv "$GIT_INDEX_FILE.new" "$GIT_INDEX_FILE"' HEAD

After you've confirmed the new history looks correct, you can add your rewritten version as a remote to your main project and merge it in using an ordinary merge.

like image 84
r3m0t Avatar answered Nov 18 '25 12:11

r3m0t



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!