Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Showing the latest changes of each subdirectory in git

Tags:

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.

Can I do this by command line in git?

like image 841
Deqing Avatar asked Jun 09 '13 08:06

Deqing


People also ask

How can I see when my git change was last?

If you want to see what's happened recently in your project, you can use git log . This command will output a list of the latest commits in chronological order, with the latest commit first.

Does git track subdirectory?

Git can version control all files and subdirectorires within your working directory. Working with subdirectories is identical to working with files. Move the HEAD to the latest commit of the master branch.

How do you see the changes of a commit in git?

Find what file changed in a commit To find out which files changed in a given commit, use the git log --raw command.

What is subdirectory in git?

git. Git uses this special subdirectory to store all the information about the project, including the tracked files and sub-directories located within the project's directory. If we ever delete the . git subdirectory, we will lose the project's history. Next, we will change the default branch to be called main .


2 Answers

Thanks answers from Klas Mellbourn and Nevik Rehnel, finally I combined these two versions into mine:

#!/bin/bash

FILES=`ls -A`
MAXLEN=0
for f in $FILES; do
    if [ ${#f} -gt $MAXLEN ]; then
        MAXLEN=${#f}
    fi
done
for f in $FILES; do
    str=$(git log -1 --format="%cr      [%cn]   %s" $f)
    printf "%-${MAXLEN}s -- %s\n" "$f" "$str"
done

Outputs:

$ bash view.bash
android_webview   -- 4 months ago       [[email protected]]    Disable testCalledForIframeUnsupportedSchemeNavigations
ash               -- 4 months ago       [[email protected]]   Rename _hot_ -> _hover_
cc                -- 4 months ago       [[email protected]]     cc: Let impl-side painting use smaller tiles
chrome            -- 5 weeks ago        [Deqing]     Set the nacl pipe to non-blocking
tools             -- 10 weeks ago       [Haxx Hx]    Add submodule tools/gyp
like image 66
Deqing Avatar answered Sep 18 '22 12:09

Deqing


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" $_)
}

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.

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

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
like image 26
12 revs Avatar answered Sep 22 '22 12:09

12 revs