Howto "git ls" files marked by git as "deleted by us"

Viewed 171

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:

  • actually I am using git svn; to connect to some backend SVN server
  • SVN trunk contains directories A, B, C
  • I am making changes on trunk that affect all three directories
  • But: the git where I run the cherry-pick ... actually resembles "product branches" created on the SVN server. These "product" branches do only contain subsets (so one has A and B; the other has B and C).
  • I tried hard; but I really couldn't get to create a git svn clone that contains SVN trunk AND SVN product branches at the same time
2 Answers

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.

Related