Skip to content

Instantly share code, notes, and snippets.

@hello-josh
Last active May 27, 2025 19:40
Show Gist options
  • Select an option

  • Save hello-josh/dbabb56e1a01ac293b83154a6f4a208e to your computer and use it in GitHub Desktop.

Select an option

Save hello-josh/dbabb56e1a01ac293b83154a6f4a208e to your computer and use it in GitHub Desktop.

Revisions

  1. hello-josh revised this gist Aug 27, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion remove-whitespace.md
    Original file line number Diff line number Diff line change
    @@ -24,6 +24,6 @@ How to remove whitespace-only changes from a PR

    git diff --cached

    7) Commit you work!
    7) Commit your work!

    git commit
  2. hello-josh revised this gist Aug 27, 2021. 1 changed file with 7 additions and 7 deletions.
    14 changes: 7 additions & 7 deletions remove-whitespace.md
    Original file line number Diff line number Diff line change
    @@ -2,28 +2,28 @@ How to remove whitespace-only changes from a PR

    1) Create a new local branch that will contain your changes without the whitespace

    git checkout -b tmp-branch
    git checkout -b tmp-branch

    2) Merge the changes that contain whitespace into your current branch WITHOUT committing the changes

    git merge <the branch with whitespace> --no-commit
    git merge <the branch with whitespace> --no-commit

    3) Create a diff that ignores whitespace and apply it to your branch. This creates a diff in unified format, ignoring whitespace, and not colorizing the output. Then using git to apply (like applying a patch) to the current directory.

    git diff -U0 -w --no-color | git apply --cached --ignore-whitespace --unidiff-zero -
    git diff -U0 -w --no-color | git apply --cached --ignore-whitespace --unidiff-zero -

    4) Remove any remaining unstaged changes. The unstaged changes are the whitespace-only changes

    git checkout .
    git checkout .

    5) Add any new files back to the staged changes since the diff/apply method ignores net-new files.

    git add .
    git add .

    6) Verify your work

    git diff --cached
    git diff --cached

    7) Commit you work!

    git commit
    git commit
  3. hello-josh created this gist Aug 27, 2021.
    29 changes: 29 additions & 0 deletions remove-whitespace.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,29 @@
    How to remove whitespace-only changes from a PR

    1) Create a new local branch that will contain your changes without the whitespace

    git checkout -b tmp-branch

    2) Merge the changes that contain whitespace into your current branch WITHOUT committing the changes

    git merge <the branch with whitespace> --no-commit

    3) Create a diff that ignores whitespace and apply it to your branch. This creates a diff in unified format, ignoring whitespace, and not colorizing the output. Then using git to apply (like applying a patch) to the current directory.

    git diff -U0 -w --no-color | git apply --cached --ignore-whitespace --unidiff-zero -

    4) Remove any remaining unstaged changes. The unstaged changes are the whitespace-only changes

    git checkout .

    5) Add any new files back to the staged changes since the diff/apply method ignores net-new files.

    git add .

    6) Verify your work

    git diff --cached

    7) Commit you work!

    git commit