赞
踩
转自 原文:http://yuanmacha.com/1955523110.html 笔记使用,侵权删。
问题
git diff --name-only或者git diff --name-status将列出所有已更改的文件,但是没有命令列出包含已更改文件的所有文件夹名称。
例如,使用此目录树:
test/
|
|__B/
|
|____b1.txt
|
|__C/
|
|____c1.txt
如果b1.txt和c1.txt已经改变了,我想获得B和C作为输出。
解决方法
这是一种方式:
git diff --name-only | xargs -L1 dirname | uniq
说明
git diff --name-only:列出所有已更改的文件
xargs -L1 dirname:删除文件名以仅保留目录
uniq:删除重复项
随意创建一个别名,这样您就不必在每次需要时输入整个命令:
alias git-diff-folders=“git diff --name-only | xargs -L1 dirname | uniq”
问题
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.
解决方法
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
Feel free to 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”
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。