smart developer
smart developer

Reputation: 49

How to remove white space file before commit and upload on git

How we can un-commit a file if there is white space change expect general change

I follow the link Commit without whitespace changes on github

Upvotes: 2

Views: 3478

Answers (1)

VonC
VonC

Reputation: 1323553

If you already committed in your local repo, you can remove whitepaces in files of your last commit with:

git rebase --whitespace=fix HEAD~

(as mentioned in "git remove trailing whitespace in new files before commit")

Note that if you already pushed the bad commit on GitHub, you would need a git push --force to publish the fixed commit: that can be problematic if others have already fetched from that same GitHub repo.


If you don't want to apply that fix to all files of a commit, but only to a specific file, before commit, you can create a patch based on its git diff, and apply that patch with the git apply --whitespace=fix option.

See "git-fix-whitespace" by Bruno Bronosky.


Update Oct. 2020 (five years later): you now have an alternative on GitHub side, using GitHub Action.
See "How to avoid whitespace being committed with GitHub?".

Upvotes: 3

Related Questions