[英]Howto "git ls" files marked by git as "deleted by us"
I started to use git cherrypick;我开始使用 git cherrypick; and as a result of that I am now (very often) facing situations that give me a lot of files marked as "deleted by us".
因此,我现在(经常)面临这样的情况,这些情况给了我很多标记为“被我们删除”的文件。
I saw this other question , that mentioned how can use git ls-files --deleted
to get a flat file list;我看到了另一个问题,其中提到了如何使用
git ls-files --deleted
来获取平面文件列表; which can then be piped to xargs rm.然后可以通过管道传输到 xargs rm。
Problem is: --deleted doesn't list those "deleted by us" files.问题是:--deleted 没有列出那些“被我们删除”的文件。
So, long story short: what is the easiest/straight forward way of removing the "deleted by us" files?所以,长话短说:删除“被我们删除”文件的最简单/直接的方法是什么?
( I really liked the git ls-files approach; as that doesn't require sed/awk magic; so there is also no worrying about getting quotes right ...) (我真的很喜欢 git ls-files 方法;因为它不需要 sed/awk 魔法;所以也不必担心正确使用引号......)
Update;更新; just to explain why this not some "XY problem" situation:
只是为了解释为什么这不是一些“XY 问题”的情况:
I don't know of a "simple" command like that for this but you can use git status
itself for this.我不知道像这样的“简单”命令,但你可以使用
git status
本身。
while read -d '' status file; do
case "$status" in
(D?)
echo "Removing $file that was deleted by us."
#rm "./$file"
;;
esac
#printf 'status: %q\nfilename: %q\n' "$status" "$file"
done < <(git status -sz)
To match only DU
and not D?
只匹配
DU
而不匹配D?
(D single-character) change the case pattern appropriately. (D 单字符) 适当更改大小写模式。
To run rm
only once use files+=("$file")
in the if
block and then rm "${files[@]}"
at the end.要仅运行
rm
一次,请在if
块中使用files+=("$file")
,然后在最后使用rm "${files[@]}"
。
To list unmerged files marked as "deleted by us" the following command can be used:要列出标记为“由我们删除”的未合并文件,可以使用以下命令:
git status --porcelain --untracked-files=no | sed --silent 's/^DU //p'
or a slightly shorter variant:或稍短的变体:
git status --porcelain -uno | sed -n 's/^DU //p'
In the output of the command git status --porcelain
the unmerged "deleted by us" files are marked with DU
.在命令
git status --porcelain
的输出中, git status --porcelain
合并的“被我们删除”文件用DU
标记。
In sed
, the option -n
suppresses printing unless explicit requested, the command s/X/Y/
substitute X (a regexp) by Y, and due to the flag p
the modified line is printed.在
sed
,除非明确要求,否则选项-n
禁止打印,命令s/X/Y/
用s/X/Y/
替换 X(正则表达式),并且由于标志p
会打印修改后的行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.