Skip to content

Instantly share code, notes, and snippets.

@mmrko
Last active March 14, 2023 21:09
Show Gist options
  • Save mmrko/7d2922ed821d45265fbd to your computer and use it in GitHub Desktop.
Save mmrko/7d2922ed821d45265fbd to your computer and use it in GitHub Desktop.
git add files ignoring whitespace
# props: https://stackoverflow.com/questions/3515597/add-only-non-whitespace-changes#answer-7149602
git diff -U0 -w --no-color | git apply --cached --ignore-whitespace --unidiff-zero
@mmrko
Copy link
Author

mmrko commented Sep 15, 2017

To add an alias (e.g. ganw) for it in your ~/.bashrc (or alike):

# ~/.bashrc
alias ganw="git diff -U0 -w --no-color | git apply --cached --ignore-whitespace --unidiff-zero"

source ~/.bashrc or open a new terminal tab to make it available.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment