git diff --name-only
or git diff --name-status
will list all files that have been changed, however there is no command to list all folder names that contain files changed.
For example, with this directory tree:
test/
|
|__B/
|
|____b1.txt
|
|__C/
|
|____c1.txt
If b1.txt
and c1.txt
have changed, I'd like to get B
and C
as the output.
To get the list of files modified (and committed!) in the current branch you can use the shortest console command using standard git: git diff --name-only master... If your local "master" branch is outdated (behind the remote), add a remote name (assuming it is "origin"): git diff --name-only origin/master...
Git will only track Files and the changes in them. So folders are tracked as part of the file changes in them. In order to create an empty folder and commit it, there have to be some files inside it.
Here's a way:
git diff --name-only | xargs -L1 dirname | uniq
Explanation
git diff --name-only
: list all changed filesxargs -L1 dirname
: remove filenames to keep only directoriesuniq
: remove duplicatesYou 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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With