I made a 2 lines of change but in git It shows more lines of changes because of whitespace. Its very difficult for us to review the exact code changes.
The below are the command that I used to push the code.
First I will pull the code base from Different repo and merge with my local. And push my changes to my fork, and raise PR.
git add .
git commit -am "changes"
git pull upstream master
git push origin master
but I didn't find any whitespace remover option in my git console as well. Only I can see "UNIFIED", "SPLIT".
Screenshot
Please find the below sample screenshot for reference.
Is there any way that we can ignore all whitespace that being commit.
Any suggestion leads?
Please note that -w option will ignoring all whitespaces before diffing, so a line like this i s a line and this is a line in each file will compare as thisisaline and will not report differences. So you should use sed to remove those whitespaces occurred at start first then do `diff -bB.
The standard solution is to use the std::remove_if algorithm to remove whitespace characters from std::string using the Erase-remove idiom technique.
You can use git diff -w | git apply --cached --ignore-whitespace
as mentioned here
EDIT:
After you make any change, rungit diff -w | git apply --cached --ignore-whitespace
thengit commit -m "your message"
Another way to look at the problem is to be more cautious with the way you stage your changes.
In your above example you're using two very broad sweeping ways to search for changes in your codebase before committing.
git add .
git commit -am "changes"
The .
parameter for add
is already staging all detected changes (not exactly, see the excellent answers here for more details), but on top of that you're using the -a
parameter for commit
, which I'd describe as redundant overkill, since you're staging ALL changes AGAIN.
Your context may make my following advice more or less practical, but you might consider adding your changed files "manually" :
# check your changes (at this point, whitespace differences should not show up)
git status
# let's assume the above line showed changes in 3 files
git add <path/to/file1> <path/to/file2> <path/to/file3>
# then commit without staging parameter
git commit -m "changes"
And if the process seems tedious to you, keep in mind that :
add -i
, which allows you to iteratively look at changes to decide what's to be actually staged.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With