Thomas Arildsen
Thomas Arildsen

Reputation: 1310

Can i do a directory listing with git, displaying latest commit dates

I am looking for something like ls -l with an extra column that shows the latest commit date of each file (possibly also shortened hash and first line of log message).

Upvotes: 3

Views: 63

Answers (2)

blue112
blue112

Reputation: 56512

Something like that could work (to be improved for non-tracked files)

for i in *; do echo -n "$i - "; git --no-pager log -1 --format='%ad' $i; done

You should run that in bash.

Upvotes: 1

poke
poke

Reputation: 388003

You can do something like this:

git ls-tree --name-only HEAD | xargs -I %% sh -c 'echo %% `git log -n 1 "--pretty=format:%C(green)%h (%cr) %C(cyan)%s%Creset" -- %%`'

This will print out the file name followed by its last commit hash and date and the subject of the commit.

I’m sure you can make this even nicer but my bash knowledge is a bit limited. My pretty PowerShell solution looks like this:

git ls-tree --name-only HEAD | % { Write-Host ("{0,-30} {1}" -f $_, (git log -n 1 "--pretty=format:%C(green)%h (%cr) %C(blue)%s%Creset" -- $_)) }

Upvotes: 4

Related Questions