You can always append corrective commits when this happens.
If this is rather a problem of different members using different setups ( e.g. tabs, spaces or spaces as tabs) then you should collectively agree on a common format for your favorite development environment, store and share it.
Or alternatively you can resort into something like prettier.io/ which integrates with many languages and tools
+1 for prettier.
Also; if you still using the cmd line, please start using a graphical git client instead. Gitkraken, sourcetree, tower, there are enough. With a graphical client it's so much more obvious what you are going to commit.
Unstage/discard all 'garbage' and only commit after reviewing the changes. No more blind git add . && git commit -m.
git add . && git commit -m
I think that it's not a matter of whether someone uses the CLI or a graphical client for this, but more the overall experience, mindset and workflow of that person.
I personally always use a git diff to see what I changed and what I want to commit. If I'm happy with all unstaged changes being committed I use git add ., but if I see "garbage", I simply use git add -p .
git add .
git add -p .
After that I do a git diff --staged and if nothing went wrong I do a simple git commit -m with a descriptive commit message. When I'm done I do a git checkout -- <file> to get rid of the garbage that I didn't commit, or a simple git reset --hard if I really don't wanna keep anything.
git diff --staged
git commit -m
git checkout -- <file>
git reset --hard
What I think is that you can be as careless with both the CLI as you can be with a graphical client, it depends on how much effort you want to put into keeping your Git history clean and organized.
We're a place where coders share, stay up-to-date and grow their careers.
We strive for transparency and don't collect excess data.