3

I love using Git to organize version control and backup all my web files in Wordpress.

After updating plugins, I'd like to get the list of changes only on the direct subfolder by using git status. Typically if doing git status will a very long line of changes including the inner of each subfolder. what I'd like is to limit the result to the subfolders with the changes inside the plugins directory.

For example, this git command:

git status project_folder/wp-content/plugins

will result to:

plugins/wpml-translation-management/classes/translation-basket/
plugins/wpml-translation-management/classes/translation-dashboard/
plugins/acfml/assets/
plugins/acfml/classes/class-wpml-acf-attachments.php
plugins/wordpress-seo/js/dist/commons-921.min.js
plugins/wordpress-seo/js/dist/components-921.min.js

Actually, the git command will make a really long list of lines like on the screenshot:

enter image description here

What I would love to know is the git command to output only:

plugins/wpml-translation-management/
plugins/acfml/
plugins/wordpress-seo/

Command such:

git status project_folder/wp-content/plugins --{display_only_direct_subfolders_with_changes}

Jed
  • 1,664
  • 8
  • 33
  • 65
  • Possible duplicate of ["git status" in brief or short format like "ls -1"?](https://stackoverflow.com/questions/31523712/git-status-in-brief-or-short-format-like-ls-1) – phd Jan 15 '19 at 06:34
  • https://stackoverflow.com/search?q=%5Bgit-status%5D+list+directories+with+changes – phd Jan 15 '19 at 06:34
  • Thank you guys for the suggested links but they aren't the ones I'm looking for. You can post in the answer if you think if its a duplicate. I think I made my question very clear. – Jed Jan 15 '19 at 07:43

1 Answers1

2

try this:

git status --porcelain | awk '{print $2}' | xargs -n 1 dirname | uniq

awk '{print $2}' 

get filename from list

xargs -n 1 dirname 

extract dir from a full path

uniq

show only unique directories

uniq can be a little slower when you have many lines

Tirex
  • 454
  • 4
  • 7
  • Awesome! Appreciate your answer @Tirex, its just have duplicates of subfolders under `plugins`. This might work for few plugin updates but it would be awesome if the list of subdirectories is limited to the direct child of the specified folder. Pretty sure that would be awesome to use for big projects. https://www.screencast.com/t/L0U9JHtOANbz – Jed Jan 15 '19 at 08:53
  • 1
    Can't reproduce on my computer. But try to add `sort` before `uniq` i think it is fix duplicate problem. 'git status --porcelain | awk '{print $2}' | xargs -n 1 dirname | sort | uniq' – Tirex Jan 15 '19 at 09:49
  • I have run `$ git status plugins --porcelain | awk '{print $2}' | xargs -n 1 dirname | sort | uniq` Give almost the same except it got sorted from shortest to longest lines per directory: https://www.screencast.com/t/QfLpMxb3 Is there any way for me to show only the direct descendants of the `plugins` folder? – Jed Jan 16 '19 at 06:51
  • Sorry, I'm referring to the depth of the results which do not include files or subfolders for each plugin. – Jed Jan 16 '19 at 06:55
  • 2
    try this `git status --porcelain | awk '{print $2}' | xargs -n 1 dirname | cut -f1,2,3 -d'/' | sort | uniq` – Tirex Jan 16 '19 at 07:14
  • Woah, its almost there, It just, there are some folders weren't included, see this screenshot: folder `wpml-translation-management` wasn't included in the results. https://www.screencast.com/t/sLQiSeoamP – Jed Jan 16 '19 at 08:13
  • I see an error in your screenshot (xargs unterminated quote), unfortunately can't reproduce it – Tirex Jan 16 '19 at 09:48