当前位置:   article > 正文

如何列出在Git中更改了文件的所有文件夹名称 (How do I list all folder names that have files changed in Git)_git 查看修改的文件名

git 查看修改的文件名

转自 原文: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”

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/羊村懒王/article/detail/120175?site
推荐阅读
相关标签
  

闽ICP备14008679号