Home > Back-end >  Is there a way to avoid superfluous space changes in git history?
Is there a way to avoid superfluous space changes in git history?

Time:03-31

If one has made a minor mistake to formatting, say indenting a line that does not need to be indented, is there a way to not have this in the commit history.

For example using git diff I can see ...

-  const getUniqueUserID = require('./websocket-user-id');
 const getUniqueUserID = require('./websocket-user-id');

which might be annoying to see in the commit history. Is this indeed just a change of 2 spaces, the formatting is hard to read.

Should I just commit this space fix with another more substantial fix?

CodePudding user response:

Are you concerned about there being an extra commit, or are you concerned with the diff being less useful?

You can use -b and -w (--ignore-space-change and --ignore-all-space) to minimize the diff, but a commit is a commit and if it's a part of the history it would be more confusing to hide it.

I tend to think it's not a big deal to make a small well-described change, even if it's whitespace-only.

CodePudding user response:

You can Simply run following command:

git diff -w | git apply --cached --ignore-whitespace 
  • Related