Smith Dwayne Smith Dwayne - 1 year ago 144
Git Question

Git delete all unmodified files

I am using git in my project at Linux platform. I have plenty of files in a particular directory. I modified some 50 above files in that directory and didn't stage and commit it. I wish to delete all other unmodified files from that directory? Is there a way to do this, using git and Linux Commands?

Answer Source

Not sure why you would want to do this.... but you can:

# Save changes to stash
git stash save

# Remove everything left
rm -rf ./*

# Checkout (restore) all of the changed files
git stash show --stat | grep -v changed | sed -e 's/|.*$//;' | xargs git checkout

# Restore the changes to those files
git stash pop
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download