I found a lot of ways to deal with the whitespace problem in Git, but all of them require some sort of action on the user side: configure Git to ignore ws changes, setup a pre-commit hook with warning, or just configure the editor to remove them automatically. But is there a way to simply ignore whitespace changes on the server side or even better to strip all whitespace silently?

Background: we have a large repository with a number of developers whom we do not want to chase and convince to reconfigure their tools, but we do not want to have any trailing whitespace in our repository. For me the solution is obvious: strip all whitespace once, and ignore any ws changes from that point on. Ideally, also strip ws in all new commits. But how can I do this?

  • Sounds like what you want is a linting tool to enforce style preferences on checked-in code.
    – jayhendren
    Commented Oct 28, 2016 at 20:04
  • 1
    Write a pre-commit hook to format files the way you want them. Let people deal with conflicts. :) Commented Oct 29, 2016 at 6:13

1 Answer 1


You can't really do this sanely. You can't modify the content of a commit; you can only create new commits. Even if this were possible, it would break git: the commits on the server would be unrelated to the history stored in local developer repositories, and nothing would ever work. You really need to perform this sort of filtering before files are added to the repository, which is why you do it client side in pre-commit hooks, etc.

A better solution is to implement an enforcement mechanism on the server: reject changes that don't meet your standards.

  • Pretty much what I expected, thanks a lot!
    – Ufos
    Commented Oct 31, 2016 at 14:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .