On Fri, Mar 06, 2009 at 01:29:38PM +0000, Csaba Henk wrote: > $ git filter-branch --commit-filter ' > if [ $# -lt 3 ] || git diff --stat $3 $1 | grep -q 'sys/dev/disk/vn/vn\.c' > then > git commit-tree "$@" > else > skip_commit "$@" > fi' HEAD Wow, I'll bet that was slow to run. And it's not really what you want. You are picking commits that changed a particular file, and then including the _whole_ tree. Remember that commits really record a tree state; we only think of them as "changes" because they point to a prior commit with its own tree state. So you are just selecting some subset of the states, but not cutting down the tree in each state. What you really want to do is say: - for every commit, narrow the tree to _just_ the one file - if there were no changes in the narrowed tree, just throw out the commit You can use an --index-filter to do the former, and a --commit-filter to do the latter (or just use --prune-empty, which is a shorthand). Another poster had a similar problem, and you can see the right filter-branch recipe there: http://article.gmane.org/gmane.comp.version-control.git/111991 > * * * > > OK, I then tried to do more RTFM and be more clever and efficient, and > find a way to specify directly those commits which affect vn.c. As "git > rev-list" can be invoked like "git rev-list <commit> <path>", and the > synopsis of "git filter-branch" is like > > git filter-branch [options] [--] [<rev-list options>...] > > I then gave a try to: > > $ git filter-branch -- master sys/dev/disk/vn/vn.c > > but no dice -- I got: > > fatal: ambiguous argument 'sys/dev/disk/vn/vn.c': unknown revision or > path not in the working tree. > Use '--' to separate paths from revisions > Could not get the commits > > Any idea? I think you need an extra '--' to separate the paths from the revisions in the rev-list arguments: git filter-branch -- master -- sys/dev/disk/vn/vn.c but even that doesn't quite do what you want. It limits the commits that are shown, similar to your first attempt above, but it doesn't cut down the tree itself (OTOH, limiting by path rather than using --prune-empty is likely to run faster, since you won't even look at commits that are uninteresting. However, it may change the shape of your history with respect to branching and merging). -Peff -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html