git-subtree without squash:查看日志 [英] git-subtree without squash: view log

查看:115
本文介绍了git-subtree without squash:查看日志的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过使用git subtree add而不使用压扁选项来将一棵树合并到我的存储库中。一个git日志显示提交已成功添加到存储库。但是,如果我执行 git log --follow filename ,则历史记录停止在合并处,并且不显示以前的提交。我尝试使用 -M 而不是 - 遵循,这也不起作用。如何从合并之前获得特定文件或文件的提交日志?

解决方案

实际上, git log --follow 与子树合并一起工作,但它已知很长一段时间会被破解[1-3]。



可以坚持子树合并和休息,以保证策略对追踪多个历史有效,并耐心等待 git log --follow 会改善。这实际上可能是一个可行的决定,因为目前 git log --follow 可以在非常有用的案例中看到一些历史记录。假设您将文件从顶级回购库移至子回购库,那么它可以跟踪整个移动。如果您想跟踪特定于子回购的历史记录,则必须拥有单独的副本或签出子回购分行。



替代品和解决方法



您可以获取这样的文件的日志[1]:

  git log  - '* filename'#from thevelvel 

这会查看每次触发的提交名称
filename 结尾的文件。它不会跟随实际的重命名,并且如果您有多个文件具有相同的基本名称[1],则可能显示false
positive。



您也可以合并存储库使用不同的策略。
Ref [4]显示了一种方法,它与常规子树合并非常接近,但具有可追踪的历史记录。基本上,您可以:


  1. 将每个子存储库作为常规远程,无git子树或readtree添加,提取并合并到顶级存储库。首先,这会将你的根目录视为是他们的根目录,所以这应该在项目开始时进行。
  2. code>子回购文件分开文件夹

然后:


  • 上游更改可以正常提取和合并,但 -Xsubtree 标志用于git merge。

  • 其他情况应该类似。我已经测试过推动上游,它的工作原理,见[4]中的评论。



参考文献



[1]从git邮件列表
http://git.661346.n2.nabble.com/Bug-Files-are-losing-history-after-subtree-merge-td7597197.html



[2]从git邮件列表
http://git.661346.n2.nabble.com/gsoc-Better-git-log-follow-support-td6188083。 html#a6188352



[3] git log --follow 已在Google Summer of Code
https://git.wiki.kernel.org /index.php/SoC2011Ideas#Better_git_log_--follow_support



[4] https://saintgimp.org / 2013/01/22 / merge-two-git-repositories-into-one-repository-without-losing-file-history


I merged a tree onto a my repository by using git subtree add without the squash option. A git log shows that the commits were successfully added to the repository. However, if I do a git log --follow filename, the history stops at the merge and does not show previous commits. I tried using -M instead of --follow and that doesn't work either. How can I get a log of the commits for a specific file or files from before the merge?

解决方案

Actually, git log --follow should work with subtree merges, but it is known to be hackish for a long time [1-3].

One can stick with subtree merges and rest asured that the strategy is valid for tracking multiple histories, and patiently wait for the unavoidable event that git log --follow will improve. This may actually be a viable decision, since at present git log --follow can see some history in very useful cases. Say you moved a file from the toplevel repo to a sub-repo, then it can track the full move. When you want to track the history that is specific to a sub-repo, you really have to have a separate copy or check out a sub-repo branch.

Alternatives and Workarounds

You can get logs for the files like this [1]:

git log -- '*filename'          # from the toplevel

This views each commit that touched a file whose name ends with filename. It won't follow actual renames, and may show false positive if you have several files with the same basename [1].

You can also merge the repositories using different strategies. Ref [4] shows a way to do this which is very close to what you have with regular subtree merging, but with traceable histories. Basically, you:

  1. add, fetch and merge each sub-repository to the toplevel repository as a regular remote, no git subtree or readtree. At first, this will polute your root dir as if it was theirs, so this is to be done at the beginning of a project's life.
  2. git mv the sub-repo files to separate folders

Then:

  • upstream changes can be fetched and merged normally, but with the -Xsubtree flag to git merge.
  • other cases should be similar. I've tested pushing upstream and it works, see comment in [4].

References

[1] From the git mailing list http://git.661346.n2.nabble.com/Bug-Files-are-losing-history-after-subtree-merge-td7597197.html

[2] From the git mailing list http://git.661346.n2.nabble.com/gsoc-Better-git-log-follow-support-td6188083.html#a6188352

[3] git log --follow has been in Google Summer of Code https://git.wiki.kernel.org/index.php/SoC2011Ideas#Better_git_log_--follow_support

[4] https://saintgimp.org/2013/01/22/merging-two-git-repositories-into-one-repository-without-losing-file-history

这篇关于git-subtree without squash:查看日志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆