git log有一个技巧 - 关注一个已经重命名的目录吗? [英] Is there a trick to git log --follow a directory which has been renamed?

查看:260
本文介绍了git log有一个技巧 - 关注一个已经重命名的目录吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

git命令在重命名后有一个有用的命令来跟踪文件,如 git log --follow path / to / some / file 。不幸的是,它只适用于单个文件。我希望能够做到相当于 git log - follow some / directory



一个这样做的方式可能是按照 git ls-tree 的输出并在循环中执行该操作,但问题在于影响多个文件的提交不会是合并成一个提交。



有没有更好的方法来做到这一点?注意:使用git 2.7.4

解决方案

不。

Git不存储目录,只存储文件。当你使用任何路径名来查看整个提交的命令,如 git log git diff 时,Git基本上会说从整个提交开始,然后将其缩小到与该路径匹配的文件。这里的目录只是选择目录中的每个文件。



- 跟着选项只能跟随一个文件。所以如果你能以某种方式设法将它应用到目录中,Git会首先将目录转换为一组文件,然后选择其中一个文件并遵循那个文件。



(实际的 - 遵循的代码非常黑客,它利用了重命名检测代码,但只适用于比较新代码时提交的代码,旧的顺序:如果添加 - reverse - follow 根本不起作用。被抛出并重新编码,也许通过重新编码它,你可以使它处理多个文件名,甚至包含充满文件的目录。)


The git command has a useful command to follow a file after a rename, as in git log --follow path/to/some/file. Unfortunately, it works only for an individual file. I'd like to be able to do the equivalent of git log --follow some/directory.

One way of doing this would probably be to massage the output of git ls-tree and do that in a loop, but the problem then becomes that commits affecting multiple files won't be "coalesced" into one commit.

Is there a better way to do it? Note: using git 2.7.4

解决方案

No.

Git does not store directories, only files. When you use any path name to commands like git log or git diff that look at entire commits, Git essentially says "start with the whole commit, then shrink it down to file(s) matching that path". Directories here simply wind up selecting every file in the directory.

The --follow option can only follow one file. So if you could somehow manage to get it to apply to a directory, Git would first turn the directory into a set of files, then pick one of those files and follow just that one.

(The actual --follow code is terribly hacky. It leverages off the rename detection code, but only works when commits are being compared in the newer-to-older order: if you add --reverse, --follow never works at all. Probably the whole thing needs to be thrown out and re-coded. Perhaps by re-coding it, you could make it handle multiple file names, and even directories full of files.)

这篇关于git log有一个技巧 - 关注一个已经重命名的目录吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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