Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pushing to github messes up my code indentation

I primarily use Netbeans to write PHP code and as an example you can see in this example that my code indentation is horrendous. Pulling this code or push to the code doe not reflect the indentation issues seen here.

That is to say: I can push that the indentation shown in the example are not shown or reflected in the editor and the same goes for pulling.

I have my tabs set to 4 spaces in netbeans, whats going on? how can I fix this? This reflects poorly on me as a developer.

like image 959
TheWebs Avatar asked Mar 24 '23 14:03

TheWebs


2 Answers

Try this

Visual Studio Code:

  • Open command palette [ctrl + shift + p] > type and select "Convert indentation to spaces"

Sublime Text:

  • Open command palette [ctrl + shift + p] > type and select "convert to space"

Netbeans:

  • Here https://netbeans.org/bugzilla/show_bug.cgi?id=143795
like image 107
MohitGhodasara Avatar answered Mar 26 '23 04:03

MohitGhodasara


You are mixing tabs and spaces for indention. TAB, ascii character 9, is a different character than Space, ascii character 32. There are two settings your editor has related to using tabs:

  1. How many columns should a tab display as. You have this configured at 4 columns. GitHub displays tabs as 8 columns. That's why things look different.
  2. What does hitting the Tab key do? You can configure your editor to insert either a literal TAB character or some number of spaces when you hit the Tab key.

I won't start a tabs vs. spaces holy war here, but you probably want to use either only tabs or only spaces for indentation. If you use spaces, your code will look the same to everyone. If you use tabs, different people can change the width of a tab in their editor to view the code differently.

like image 26
Peter Lundgren Avatar answered Mar 26 '23 05:03

Peter Lundgren