Skip to content

Instantly share code, notes, and snippets.

@hhutch
Created September 10, 2012 04:01
Show Gist options
  • Save hhutch/3688814 to your computer and use it in GitHub Desktop.
Save hhutch/3688814 to your computer and use it in GitHub Desktop.
find file changes in all forks of a github repo
curl -i https://api.github.com/repos/scrooloose/nerdtree/forks |grep -e "git_url" |awk '{gsub(/,/,"");split($2,a,"/"); system("mkdir "a[4]"; cd "a[4]"; git clone " $2);}'
DIRS=$(find * -type d -name '*nerdtree' -maxdepth 1 -print)
FILECHANGE="plugin/NERD_tree.vim"
for d in $DIRS
do
cd $d
git fetch
BRANCHES=$(git branch -a)
OBS=$(git branch -r |egrep -v '(HEAD)')
for ob in $OBS
do
git checkout -t $ob 2>/dev/null
bonly=$(echo $ob |awk {'split($0,a,"/"); print a[2]'})
git checkout $bonly &>/dev/null
git pull &>/dev/null
out=$(git log --pretty=format:"%H %ad" $FILECHANGING |head -n1 | xargs -I{} echo `pwd`"("$ob"): "{})
echo $out
done
cd ../..
done
#1 mkdir $working_dir; echo "modify fetch-repos.sh for your source repo"; cd $working_dir; bash fetch-repos.sh;
#2 echo "modify find-file-changes.sh to use the file you need"; cd $working_dir; bash find-file-changes.sh > all-branch-changes.txt
#3 cat all-branch-changes.txt |sort -k4M,7
This will output a list of fork:branche:commit for a specific file sorted by date of commit;
Note: this is kind of brittle and could break depending on the input data (ie the names of things in the repositories).
@electronicsguy
Copy link

electronicsguy commented Dec 11, 2016

Thanks. This helps immensely!. Though the find gives errors sometimes. This is a better option: DIRS=$(find . -maxdepth 2 -type d -name '*nerdtree' -print)

@bmarotta
Copy link

bmarotta commented Jan 4, 2022

I had a different use case. I needed to output all the diffs for a given file. Here follows my solution. It replaces the find-file-changes.sh

DIRS=$(find * -type d -name 'J2M' -maxdepth 2 -print)
FILECHANGE="index.js"
ORIGINAL=https://github.com/kylefarris/J2M.git
for d in $DIRS
do
	cd $d
        git fetch
	git remote add original $ORIGINAL
	git fetch original
	CURR_REP=$(pwd | rev | cut -f2 -d'/' - | rev)
	echo output to $CURR_REP
	git diff --ignore-cr-at-eol --ignore-space-at-eol -b -w --ignore-blank-lines HEAD original/master index.js --output=../../$CURR_REP.diff
        cd ../..
done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment