Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git diff - only show which directories changed

Tags:

git

Is there a way to list only the directories that were changed?

If I'm at the git root say, ~/project

Files I changed are

~/project/subtool/file1

~/project/subtool/file2

~/project/subtool3/file1

I just want

~/project/subtool

~/project/subtool3

like image 932
Nishant Roy Avatar asked May 20 '18 23:05

Nishant Roy


People also ask

What is git diff -- name only?

The -z to with git diff --name-only means to output the list of files separated with NUL bytes instead of newlines, just in case your filenames have unusual characters in them. The -0 to xargs says to interpret standard input as a NUL-separated list of parameters.

How do I diff two folders in git?

Meld lets you compare two or three folders side-by-side. You can start a new folder comparison by selecting the File ▸ New... menu item, and clicking on the Directory Comparison tab. (from here).


1 Answers

You could use git-diff with the --dirstat parameter.

In your scenario, let's say you have the following commit:

$ git diff --name-status HEAD~1
M       subtool/file1
M       subtool/file2
M       subtool3/file1

It would produce the following output:

$ git diff --dirstat=files,0 HEAD~1
  66.6% subtool/
  33.3% subtool3/

Make sure to add ,0, otherwise git diff will by default only show directories with at least 3% changes. I also chose files as this is the computationally cheapest option and you do not seem to care about specific changes anyway.

If you are able to use sed you can get rid of the percentage values (you may want to tweak the regular expression a bit to fit your needs):

$ git diff --dirstat=files,0 HEAD~1 | sed 's/^[ 0-9.]\+% //g'
subtool/
subtool3/
like image 170
Marvin Avatar answered Oct 07 '22 12:10

Marvin