how to undo all whitespace changes with git

后端 未结 4 980
挽巷
挽巷 2021-01-31 14:54

I have a git repo, where I replaced a lot of files locally.

git status now shows many many modified files.

Some are \"really modified\", others only differ by li

4条回答
  •  误落风尘
    2021-01-31 15:16

    Though it seems you were originally looking for a pipe-based solution and you got it from @aristotle-pagaltzis, since it's a bit hard to remember, I think this alternative is worth noting:

    git diff -b > gitdiffb
    git stash  # or git reset --hard if you feel confident
    git apply --ignore-space-change gitdiffb
    

    If not just changes to whitespace numbers, but also whitespaces that are completely new or completely removed should be ignored, replace -b by -w.

    The outcome differs from the pipe-based solution in the removal of whitespace changes even in files that also contain relevant changes. Thus, it's not exactly the way you described it, but for most people coming here via a search engine are probably rather looking for this.

提交回复
热议问题