0

Sometimes my pull request looks HUGE because of indentation or whitespace changes. For example, if I work on a file with 2-space indentation and then my editor automatically converts it to 4-space, it will appear that nearly the entire file is changed.

How can I revert only the whitespace in a file before sending someone a pull request?

Note, I did see this answer but it's about ignoring changed whitespace after it's on GitHub. I'm looking for how to revert the whitespace before the commit.

Community
  • 1
  • 1
Alex Shroyer
  • 3,499
  • 2
  • 28
  • 54
  • 1
    If I understood correctly you should look into `pre-commit hook` in git. More about hooks could be found [here](http://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks) – Bogdan Kuštan Dec 23 '14 at 17:47

1 Answers1

2

I'm afraid there cannot be a general solution.

  • Either tell your editor not to touch formatting
  • or tell your editor to use the "correct" formatting

If your editor is making arbitrary whitespace changes and especially line breakes (like eclipse with unsuitable formatting rules) you really cannot revert those changes in a meaningful way.

If you really want to try to. You can use git log or git show with the -w option. This generates a diff removing all obvious whitespace changes (like your indentation one).

You could use this to write your own pre-commit hook, but it's probably easier and more reliable to go with the first two options.

michas
  • 25,361
  • 15
  • 76
  • 121