0

I've got a problem where I've got a large commit which changes about a thousand lines of code.

I use Intellij IDEA for coding. Problems with tabs appear when updating project, checkout on another branch, etc. This entails adding a lot of files to the Local Changes list. While the built-in diff tool shows "Contents are identical"

git diff returns this, for example

-       trailingComma: 'es5',
-       useTabs: true,
-       singleQuote: true,
+    trailingComma: 'es5',
+    useTabs: true,
+    singleQuote: true,

Maybe, the problem is in the configuration file

I enclose my global config below

core.filemode=false
filter.lfs.smudge=git-lfs smudge -- %f
filter.lfs.process=git-lfs filter-process
filter.lfs.required=true
filter.lfs.clean=git-lfs clean -- %f
credential.helper=osxkeychain
filter.tabspace.smudge=unexpand -t 4
filter.tabspace.clean=expand -t 4
filter.tabspace2.smudge=unexpand -t 2
filter.tabspace2.clean=expand -t 2

Is there any way that git can be set up to ignore whitespace change?

victriar
  • 3
  • 1
  • This has been [answered before](https://stackoverflow.com/questions/12427779/how-do-you-make-git-ignore-spaces-and-tabs) – subhacom Apr 24 '20 at 22:48

1 Answers1

0

If you want to add only certain parts of a change, you can use git add -p to interactively step through each hunk and select only the changes that you want.

However, in your case, this is still going to be a bunch of hassle, and Git doesn't provide a better option here. It is possible to use a smudge/clean filter for adjusting code, but that won't work here because the filter doesn't know what format the existing code is in.

If the existing code already meets the standards of your project, then it's better to fix your editor so it doesn't reformat code needlessly. Most editors have these settings and can be configured appropriately. You could consider adding an .editorconfig file to your repository to tell everyone what those standards are, or use a suitable code formatting tool that everyone's required to run before check-in (possibly backed with a CI check).

If the problem is that the existing code doesn't meet the standards of your project, then it would be better to create a single initial commit that formats the code according to your project's standards and that contains no other changes, and then make your change in a second, followup commit.

bk2204
  • 64,793
  • 6
  • 84
  • 100