How do I list all folder names that have files changed in Git? How do I list all folder names that have files changed in Git? shell shell

How do I list all folder names that have files changed in Git?


Here's a way:

git diff --name-only | xargs -L1 dirname | uniq

Explanation

  • git diff --name-only: list all changed files
  • xargs -L1 dirname: remove filenames to keep only directories
  • uniq: remove duplicates

You can create an alias so you don't have to type the whole command each time you need it:

alias git-diff-folders="git diff --name-only | xargs -L1 dirname | uniq"


This command would give results of top level directories. git status | cut -d'/' -f1

For a more in depth solution I am currently working with ${PWD##*/} in bash to find a more correct solution to your problem.

Trying to write a solution for you in git that is simular to this npm solution:

get the path where npm gulp called from

im no longer searching for the answer on this one,

git diff --name-only | xargs -L1 dirname | uniq

was the correct answer provided by Pᴇʜ

it works on my mac computer after his edit's