tags:

views:

53

answers:

2

I tried to diff only .cs files, I use: git diff HEAD -- ./*.cs It just didn't work. Note there are several cs files under different directories. What is the correct command?

Thanks!


I use msysgit in windows. I decided to write a python script for it. Here it is:

import os
screenOutput = os.popen('git status').read()
lines =screenOutput.splitlines()
keyword = 'modified:'
cmd = 'git diff HEAD -- '
for line in lines:
    index = line.find(keyword)
    if(index >= 0):
        line = line[index + len(keyword) + 1:].strip()
        if(line.endswith('.cs')):
            cmd += (line + ' ')
os.system(cmd)     

The script captures the 'git status' output, searches the line with the keyword 'modified:', and gets the modified file names. It's ugly. But it works. And it can be extended to handle arguments.

+2  A: 

I might try git diff HEAD -- $(find . -name '*.cs') so that you're giving it the full paths to each. Not sure if that will work, but it might do the trick.

Daenyth
If you are trying to do this for git diff head~5 head, it will not find any .cs files that were deleted before head and match the pattern you want.
adymitruk
That's an excellent point. A more complete answer would probably involve some kind of shell script that parses `git log` and gets the diff targets that way. The question seemed to be more along the lines of "find all unstaged/uncommitted .cs files and show the diffs", so that's what my answer leans towards
Daenyth
+1  A: 

git diff **/*.cs did it for me.

Alexander Groß
This is probably bash 4 specific, as the `**` glob was only added then. It should work in zsh though.
Daenyth
This does not work in MSysGit on windows. Their implementation of bash is equivalent to something earlier than bash 4.
adymitruk
Ah, well. I use zsh which supports globs in file paths. That might explain why it does not work with msysgit and older Bash-based shells.
Alexander Groß