Question:
I have 57 local branches. I know I made a change to a certain file in one of them, but I’m not sure which one. Is there some kind of command I can run to find which branches contain changes to a certain file?
Answer:
Find all branches which contain a change to FILENAME (even if before the (non-recorded) branch point)
1 2 3 |
FILENAME=" git log --all --format=%H $FILENAME | while read f; do git branch --contains $f; done | sort -u |
Manually inspect:
1 2 |
gitk --all --date-order -- $FILENAME |
Find all changes to FILENAME not merged to master:
1 2 |
git for-each-ref --format="%(refname:short)" refs/heads | grep -v master | while read br; do git cherry master $br | while read x h; do if [ "`git log -n 1 --format=%H $h -- $FILENAME`" = "$h" ]; then echo $br; fi; done; done | sort -u |