显示git中每个子目录的最新更改 [英] Showing the latest changes of each subdirectory in git
问题描述
在 github 中,如果您打开存储库,则会看到一个页面,显示每个子目录和文件的最新提交和时间。
In github if you open a repository you will see a page showing the latest commit and time of each subdirectory and file.
我可以通过命令行在git中执行此操作吗?
Can I do this by command line in git?
推荐答案
在PowerShell中,您可以创建一个如下所示的脚本:
In PowerShell you could create a script like this
git ls-tree --name-only HEAD | ForEach-Object {
Write-Host $_ "`t" (git log -1 --format="%cr`t%s" $_)
}
循环遍历当前目录中的所有文件,写出文件名称,选项卡(反引号t),然后使用相对日期,选项卡和提交消息输出 git log
。
This loops through all files in the current directory, writes out the file name, a tab (the backquoted "t"), and then the output of git log
with the relative date, a tab, and the commit message.
示例输出: p>
Sample output:
subfolder 18 hours ago folder for miscellaneous stuff included
foo.txt 3 days ago foo is important
.gitignore 3 months ago gitignore added
GitHub结果实际上也包含提交者,您也可以通过添加 [%cn]
:
The GitHub result actually contains the committer too, you can get that also by adding [%cn]
:
Write-Host $_ "`t" (git log -1 --format="%cr`t%s`t[%cn]" $_)
上面的脚本不能很好地处理长文件名,因为它取决于制表符。这里是一个脚本,它创建了一个格式良好的表格,其中每列的宽度都与它所需要的一样宽:
The script above does not handle long filenames well, since it depends on tabs. Here is a script that creates a nicely formatted table, where each column is exactly as wide as it needs to be:
git ls-tree --name-only HEAD | ForEach-Object {
Write-Output ($_ + "|" + (git log -1 --format="%cr|%s" $_))
} | ForEach-Object {
New-Object PSObject -Property @{
Name = $_.Split('|')[0]
Time = $_.Split('|')[1]
Message = $_.Split('|')[2]
}
} | Format-Table -Auto -Property Name, Time, Message
这篇关于显示git中每个子目录的最新更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!