Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Strange indenting for Java Eclipse project on Github

Tags:

github

Everything is good in Eclipse, indenting is fine. Then I put my code on github and for some reason the indenting was a mess. I am not sure what is going on?

Thanks

like image 564
user1796942 Avatar asked Jan 29 '26 19:01

user1796942


2 Answers

If those indentation issues are reflected back in your code after a git push to GitHub, you either have:

  • a hook removing spaces before tab (as in "Make git automatically remove trailing whitespace before committing")
  • or a filter content driver declared ina .gitattributes file (as in "Can git automatically switch between spaces and tabs?")

Those are the two automatic mechanisms that could explain a change during the git commit.


But if your code looks fine locally after the git push, but looks not fine on GitHub, then you must have a combination of space and tabs correctly rendered locally, and rendered differently on GitHub.

As mentioned in "Indentation issue using sublime text 2":

The problem is not hard tabs, the problem is mixing spaces and tabs for indentation.

like image 104
VonC Avatar answered Feb 01 '26 16:02

VonC


I got this working in eclipse:

Eclipse Settings:

  • Preferences : Java -> Code Style -> Formatter
  • Create new profile
  • Update profile indent settings:

enter image description here

Update Existing Java Source:

  • (Toolbar) Source : Correct Indentation
  • Check file, you should see all indentations use spaces, not tabs
like image 39
raffian Avatar answered Feb 01 '26 16:02

raffian



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!