git undo alias with xargs

Posted by ABach on Stack Overflow See other posts from Stack Overflow or by ABach
Published on 2010-05-05T20:43:39Z Indexed on 2010/05/05 20:48 UTC
Read the original article Hit count: 316

Filed under:
|
|

I have a git alias (git undo) that undoes everything in the working directory, including new files, changed files, and deleted files:

!git reset --hard && git ls-files -d | xargs -0 git rm --ignore-unmatch && git clean -fq

On OS X, this works great. On Linux, however, I run into the following issue: if no files have been deleted from the repository, the git ls-files -d | xargs -0 git rm --ignore-unmatch command will fail (xargs will be passed nothing).

Is there a way to have xargs silently move on if it receives nothing from git ls-files?

© Stack Overflow or respective owner

Related posts about git

Related posts about alias