I started to use 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; which can then be piped to xargs rm.
Problem is: --deleted doesn't list those "deleted by us" files.
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 ...)
Update; just to explain why this not some "XY problem" situation:
I don't know of a "simple" command like that for this but you can use git status
itself for this.
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?
(D single-character) change the case pattern appropriately.
To run rm
only once use files+=("$file")
in the if
block and then rm "${files[@]}"
at the end.
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
.
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.