我几乎使用了所有的git log命令,但是我还没有找到最好的方法来做这件事。我只需要获取文件名和路径,不需要其他信息。
/path/filename.txt
/path/anotherfile.ext
...
...
我需要在git log命令中输入日期FROM和TO。但是,git log会给出开发者名称、日期、提交编号或其他我不想要的信息,但我只想要文件名和完整路径,应该如何获取?
使用--name-only
选项,并移除空格式的消息。
git log --name-only --format=""
按照惯例使用所有其他git log
选项。例如:
只需像往常一样使用所有其他git log
选项即可。例如:
git log --name-only --format="" -n 2 master
可选择排序并去重
git log --name-only --format="" | sort | uniq
--since
和--until
选项来选择时间范围,然后可以使用UNIX管道来进行grep
、sort
和收集uniq
路径:git log --name-status --since='..' --until='..' | grep -E '^[A-Z]\b' | sort | uniq | sed -e 's/^\w\t*\ *//'
例子:
git log --name-status --since='1 January 2015' --until='2 January 2015' | grep -E '^[A-Z]\b' | sort | uniq | sed -e 's/^\w\t*\ *//'
git diff
和--name-only
。git diff hash1..hash2 --name-only
sed
魔法(请参见编辑):... | sed -e 's/^\w\t*\ *//'
- Ionică Bizăugit
可以作为可执行文件访问。 - Ionică Bizău这个方法不使用 git log
,但是如果你愿意使用提交对象(哈希值、分支引用或其他提交标识符),git diff
可以很简单地实现。以下是获取最近三次提交的更改文件示例。
$ git diff HEAD~3 --name-only
> some/path/with/file.php
> another/path/and/file.html
> yet/another.json
您可以用单个commitish替换HEAD~3,这样您就可以将其与当前HEAD(您正在的提交)进行比较,或者使用<commitish>..<commitish>
定义一个提交范围:
$ git diff HEAD..abcd1234 --name-only
> file/name/here.cpp
$ git diff 1234abcd..abcd1234 --name-only
> some/file/name-here.txt
--diff-filter
选项。查看 git diff
的手册:--diff-filter=[(A|C|D|M|R|T|U|X|B)...[*]]
Select only files that are Added (A), Copied (C), Deleted (D), Modified (M), Renamed (R), have their type (i.e. regular file, symlink, submodule, ...) changed (T), are
Unmerged (U), are Unknown (X), or have had their pairing Broken (B). Any combination of the filter characters (including none) can be used. When * (All-or-none) is added
to the combination, all paths are selected if there is any file that matches other criteria in the comparison; if there is no file that matches other criteria, nothing
is selected.
如果您需要使用日期进行过滤,则这可能不是最佳选择。也许可以使用 git log --since=...
获取日期的第一个哈希值,并将其传递给 git diff
?