Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
552 views
in Technique[技术] by (71.8m points)

wordpress - Git Status - List only the direct subfolders with changes, not inner files

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}

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...