如何显示 git repo 子目录的 git log 历史记录?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16343659/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to show git log history for a sub directory of a git repo?
提问by ams
Lets say that I have a git repo that looks like this.
假设我有一个看起来像这样的 git repo。
foo/
.git/
A/
... big tree here
B/
... big tree here
Is there a way to ask git log to show only the log messages for a specific directory. For example I want to see what commits touched files in foo/A only?
有没有办法让 git log 只显示特定目录的日志消息。例如,我只想查看 foo/A 中哪些提交触及文件?
回答by GoZoner
From directory foo/
, use
从目录foo/
,使用
git log -- A
You need the '--' to separate <path>..
from the <since>..<until>
refspecs.
您需要'--'<path>..
与<since>..<until>
refspecs分开。
# Show changes for src/nvfs
$ git log --oneline -- src/nvfs
d6f6b3b Changes for Mac OS X
803fcc3 Initial Commit
# Show all changes (one additional commit besides in src/nvfs).
$ git log --oneline
d6f6b3b Changes for Mac OS X
96cbb79 gitignore
803fcc3 Initial Commit
回答by Nick Tomlin
You can use git log
with the pathnames of the respective folders:
您可以使用git log
相应文件夹的路径名:
git log A B
git log A B
The log will only show commits made in A
and B
. I usually throw in --stat
to make things a little prettier, which helps for quick commit reviews.
日志将只显示在A
和 中进行的提交B
。我通常--stat
会让事情变得更漂亮一点,这有助于快速提交。
回答by Nikhil Agarwal
Enter
进入
git log .
git log .
from the specific directory, it also gives commits in that directory.
从特定目录,它还提供该目录中的提交。
回答by Mafu Josh
For tracking changes to a folder where the folder was moved, I started using:
为了跟踪移动文件夹的文件夹的更改,我开始使用:
git rev-list --all --pretty=oneline -- "*/foo/subfoo/*"
This isn't perfect as it will grab other folders with the same name, but if it is unique, then it seems to work.
这并不完美,因为它会抓取具有相同名称的其他文件夹,但如果它是唯一的,那么它似乎可以工作。
回答by Matthias M
The other answers only show the changed files.
其他答案仅显示更改的文件。
git log -p DIR
is very useful, if you need the full diffof all changed files in a specific subdirectory.
git log -p DIR
非常有用,如果您需要特定子目录中所有更改文件的完整差异。
Example: Show all detailed changes in a specific version range
示例:显示特定版本范围内的所有详细更改
git log -p 8a5fb..HEAD -- A B
commit 62ad8c5d
Author: Scott Tiger
Date: Mon Nov 27 14:25:29 2017 +0100
My comment
...
@@ -216,6 +216,10 @@ public class MyClass {
+ Added
- Deleted