How to use git diff to only diff .cs files
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:
开发者_StackOverflow社区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.
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.
git diff HEAD -- "*.cs"
should work.
git diff **/*.cs
did it for me.
精彩评论