Skip to content

Instantly share code, notes, and snippets.

@seaders
Last active August 29, 2015 14:23
Show Gist options
  • Select an option

  • Save seaders/bfae8312061df071114f to your computer and use it in GitHub Desktop.

Select an option

Save seaders/bfae8312061df071114f to your computer and use it in GitHub Desktop.
If you've a big dirty git workspace, with loads of documents with whitespace (which you know you can safely commit), you can use python's sh library (https://github.com/amoffat/sh) and the script below to safely stage all files with only whitespace changes
#!/usr/bin/python
import sh
git = sh.git.bake('--no-pager', # @UndefinedVariable
_cwd='/Developer/repos/git/example')
for fname in git.diff('--name-only', '--full-index', 'HEAD').splitlines():
if '' == git.diff('-w', fname):
print 'adding', fname
git.add(fname)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment