在读取树合并后,Git日志显示很少 [英] Git log shows very little after doing a read-tree merge
问题描述
git remote add - f Bproject / path / to / B
git merge -s我们的--no-commit Bproject / master
git读取树--prefix = dir-B / -u Bproject / master
git commit -m合并B项目作为我们的子目录
尽管这似乎有些微妙的问题。当我做的时候
git log dir-B /
结果就是合并B项目作为我们的子目录消息。如何获取我想要的日志信息,即dir-B的导入历史记录?
您的合并提交显示 example.txt
在 BProject / master
中被重命名为 dir-B / example.txt
。除非使用 - follow
选项,否则 git log
不会跟随过去重命名的文件/目录的历史记录: - 关注
继续列出超出重命名范围的文件历史记录(仅适用于单个文件)。
如果您真的急于正确显示差异,您可以重写 Bproject / master
历史记录,好像项目一直位于目录 dir-B
中,然后进行普通合并。这意味着合并历史的SHA与 Bproject / master
中的SHA没有任何关系!虽然时间戳,作者和提交信息都将保留原始值。
如果您想这样做,我会建议克隆 Bproject
>然后在该克隆中运行:
git-filter-branch manpage
将整个树移动到一个子目录中,或者从这里删除:
git filter-branch --index-filter \
'git ls-files -s | seds-\ t \* - & newsubdir / - |
GIT_INDEX_FILE = $ GIT_INDEX_FILE.new \
git update-index --index-info&&
mv$ GIT_INDEX_FILE.new$ GIT_INDEX_FILE'HEAD
确认新的历史看起来是正确的,您可以将您的重写版本作为远程主机添加到您的主项目中,并使用普通合并进行合并。
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?
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.
这篇关于在读取树合并后,Git日志显示很少的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!