How can I find any commits that contain (do not touch) a file in git?

advertisements

In git, how do I work back from a branch head and find every commit that contains (not necessarily touches) a particular file please? The "touches" version is ok to write:

git log mybranch -- filename | grep "^commit" | awk '{print $2}'

For what I'm trying to do, though, namely building all of the revisions that contain a particular file (a pom.xml), this isn't enough. Any ideas?


Here's a quick-and-dirty bash solution. It fetches a list of all commit ids reachable from any branch, iterates over them, checking out each commit. If the file exists after checking out the commit, it prints out that commit id.

This will destroy your working directory via git checkout -f. Stash your changes before running it.

for x in `git log --all | grep -o "[a-z0-9]\{40\}"`
do
  git checkout -f $x &> /dev/null
  if [ -e "config/pom.xml" ]
  then
    echo $x
  fi
done