How to avoid whitespace being commit with github

前端 未结 3 1624
梦毁少年i
梦毁少年i 2021-02-04 21:10

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

3条回答
  •  囚心锁ツ
    2021-02-04 21:47

    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   
    
    # then commit without staging parameter
    git commit -m "changes"
    

    And if the process seems tedious to you, keep in mind that :

    • You can copy and paste paths straight from the right above status output, which makes it quick
    • There is also an interactive mode invoked with add -i, which allows you to iteratively look at changes to decide what's to be actually staged.

提交回复
热议问题