Snippets

Radistao A Nested git repositories scripts (batch/cmd): List changes for last week (or any period of time) for certain user with/without some commit message; show current branches

Created by Radistao A last modified
@REM show current branch for every child directory, starting from current one

@echo off 

set SCRIPT_DIR=%~dp0

setlocal EnableDelayedExpansion

for /d %%A in (%SCRIPT_DIR%*) do IF EXIST %%A\.git (
  rem echo %%A

  rem read repo name
  for %%f in (%%A) do set repoName=%%~nxf

  rem read branch name
  for /f %%i in ('git -C %%A rev-parse --abbrev-ref HEAD') do set branchName=%%i

  set ADJUST=!repoName!           x

  echo !ADJUST:~0,16! -^> !branchName!
  echo.
 )

pause
@echo off

REM list all changes by some certain user for last week.
REM put this file into root directory, where all git repositories are located.
REM if you want to use own git alias.hist config:
REM git config --global alias.hist "log --all --pretty=format:'%h %ad%x08%x08%x08%x08%x08%x08%x08%x08%x08 | %s%d [%an]' --graph --date=iso"

set AUTHOR=radistao
set SINCE=1 week ago

REM if empty - search all messages
set COMMIT_MSG=

set SCRIPT_DIR=%~dp0

pushd %SCRIPT_DIR%

for /d %%A in (%SCRIPT_DIR%*) do IF EXIST %%A\.git (
  echo.
  pushd %%A
  echo %%A

  REM use this line if you don't have own "git config alias.hist", or second line you have it.
  call git --no-pager log --all ^
  --pretty=format:"%%%%h %%%%ad | %%%%s%%%%d [%%%%an]" ^
  --graph --date=short ^
  --since="%SINCE%" --author="%AUTHOR%" --grep="%COMMIT_MSG%"
  
  REM if you have hist alias
  REM see https://gist.github.com/radistao/3d7b048bd0c011a2598a
  REM call git --no-pager hist ^
  --since="%SINCE%" --author="%AUTHOR%" --grep="%COMMIT_MSG%"

  REM if you want date in format YYYY-MM-DD HH:MM
  REM call git --no-pager log --all ^
  --pretty=format:"%%%%h %%%%ad%%%%x08%%%%x08%%%%x08%%%%x08%%%%x08%%%%x08%%%%x08%%%%x08%%%%x08 | %%%%s%%%%d [%%%%an]" --date=iso ^
  --graph --since="%SINCE%" --regexp-ignore-case --author="%AUTHOR%" --grep="%COMMIT_MSG%"

  popd
  echo. )

popd

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.