#!/bin/bash #$1 : Folder containing .git directory to scan #$2 : Folder to put files to function init_header() { cat < "$path/$name" else echo -e "\e[32m[+] Found folder: $path/$name\e[0m" mkdir -p "$path/$name"; #Recursively traverse sub trees traverse_tree $hash "$path/$name"; fi done; } function traverse_commit() { local base=$1 local commit=$2 local count=$3 #Create folder for commit data echo -e "\e[32m[+] Found commit: $commit\e[0m"; path="$base/$count-$commit" mkdir -p $path; #Add meta information git cat-file -p "$commit" > "$path/commit-meta.txt" #Try to extract contents of root tree traverse_tree $commit $path } #Current directory as we'll switch into others and need to restore it. OLDDIR=$(pwd) TARGETDIR=$2 COMMITCOUNT=0; #If we don't have an absolute path, add the prepend the CWD if [ "${TARGETDIR:0:1}" != "/" ]; then TARGETDIR="$OLDDIR/$2" fi cd $1 #Extract all object hashes find ".git/objects" -type f | sed -e "s/\///g" | sed -e "s/\.gitobjects//g" | while read object; do type=$(git cat-file -t $object) # Only analyse commit objects if [ "$type" = "commit" ]; then CURDIR=$(pwd) traverse_commit "$TARGETDIR" $object $COMMITCOUNT cd $CURDIR COMMITCOUNT=$((COMMITCOUNT+1)) fi done; cd $OLDDIR;