mirror of
https://github.com/jbranchaud/til
synced 2026-01-03 15:18:01 +00:00
Add Fix Whitespace Errors Throughout Branch Commits as a Git TIL
This commit is contained in:
@@ -10,7 +10,7 @@ pairing with smart people at Hashrocket.
|
|||||||
|
|
||||||
For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186).
|
For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186).
|
||||||
|
|
||||||
_1536 TILs and counting..._
|
_1537 TILs and counting..._
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -311,6 +311,7 @@ _1536 TILs and counting..._
|
|||||||
- [Find And Remove Files That Match A Name](git/find-and-remove-files-that-match-a-name.md)
|
- [Find And Remove Files That Match A Name](git/find-and-remove-files-that-match-a-name.md)
|
||||||
- [Find The Date That A File Was Added To The Repo](git/find-the-date-that-a-file-was-added-to-the-repo.md)
|
- [Find The Date That A File Was Added To The Repo](git/find-the-date-that-a-file-was-added-to-the-repo.md)
|
||||||
- [Find The Initial Commit](git/find-the-initial-commit.md)
|
- [Find The Initial Commit](git/find-the-initial-commit.md)
|
||||||
|
- [Fix Whitespace Errors Throughout Branch Commits](git/fix-whitespace-errors-throughout-branch-commits.md)
|
||||||
- [Get Latest Commit Timestamp For A File](git/get-latest-commit-timestamp-for-a-file.md)
|
- [Get Latest Commit Timestamp For A File](git/get-latest-commit-timestamp-for-a-file.md)
|
||||||
- [Get The Name Of The Current Branch](git/get-the-name-of-the-current-branch.md)
|
- [Get The Name Of The Current Branch](git/get-the-name-of-the-current-branch.md)
|
||||||
- [Get The Short Version Of The Latest Commit](git/get-the-short-version-of-the-latest-commit.md)
|
- [Get The Short Version Of The Latest Commit](git/get-the-short-version-of-the-latest-commit.md)
|
||||||
|
|||||||
39
git/fix-whitespace-errors-throughout-branch-commits.md
Normal file
39
git/fix-whitespace-errors-throughout-branch-commits.md
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
# Fix Whitespace Errors Throughout Branch Commits
|
||||||
|
|
||||||
|
Let's say we've been working on some changes to our repository on a branch.
|
||||||
|
We've made several commits. We are close to putting up a PR, but we want to
|
||||||
|
make sure everything is tidied up.
|
||||||
|
|
||||||
|
We run a check and see that there are some whitespace errors that should be
|
||||||
|
fixed.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ git diff main --check
|
||||||
|
README.md:1: trailing whitespace.
|
||||||
|
+# git-playground
|
||||||
|
script.sh:9: trailing whitespace.
|
||||||
|
+
|
||||||
|
```
|
||||||
|
|
||||||
|
This post isn't able to show the highlighted whitespace errors, but we can see
|
||||||
|
the warnings above.
|
||||||
|
|
||||||
|
Rather than cluttering things with an additional commit that fixes these errors
|
||||||
|
or manually cleaning up each commit, we can ask `git` to fix it for us.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ git rebase --whitespace=fix main
|
||||||
|
```
|
||||||
|
|
||||||
|
That will do a manual rebase of each commit addressing the whitespace errors.
|
||||||
|
|
||||||
|
We can run the error check again and see no output, which means we are good to
|
||||||
|
go.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ git diff main --check
|
||||||
|
```
|
||||||
|
|
||||||
|
See the section on `--whitespace` in `man git-apply` for more details.
|
||||||
|
|
||||||
|
[source](https://git-scm.com/book/en/v2/Customizing-Git-Git-Configuration)
|
||||||
Reference in New Issue
Block a user