1

After I do a git rebase, the code lines I have added/modified are indented four spaces or more to the left of the respective code block. This is incredibly annoying and time-consuming to fix, not to mention it makes it unreadable for Objective-C (imagine if I was coding in python...?)

Xcode (or whatever, git?) adds in tabs in place of the spaces, and my Xcode is set to make tabs spaces.

No one at my work seems to have a good answer for why it occurs. I made trustctime false, but that did not help. Any help?

jheld
  • 148
  • 2
  • 8
  • Wait, you're saying that if you add some lines, commit, and rebase, those lines change during the rebase? Do you have any config options set about whitespace in your ~/.gitconfig or other git config places? – Jesse Rusak Mar 26 '13 at 21:26
  • The core.whitespace I believe I've never touched (and I have it printed out in one of the below answers). The apply.whitespace has been changed, but the issue was occurring before I changed it at all. I thought maybe it had to do with Xcode 4.6, because I don't remember this occurring with 4.5, but maybe I just never realized (did one rebase and moved on blindly). What sort of whitespace options were you referring to? – jheld Mar 27 '13 at 13:20

3 Answers3

2

This could be a whitespace setting. Check out the options for core.whitespace on the git-config man page. If you have that set as well as apply.whitespace, then git will do things to your whitespace, probably including during a rebase.

Try finding out what git config core.whitespace and git config apply.whitespace are and modify them in your ~/.gitconfig file or with something like:

git config --global apply.whitespace nowarn
Jesse Rusak
  • 56,530
  • 12
  • 101
  • 102
  • My apply.whitespace was "strip", mostly due to one of my colleagues saying in an email that it was something we should enact. The core.whitespace is space-before-tab,indent-with-non-tab,trailing-space. I'll try the apply.whitespace as false and see what that does. – jheld Mar 27 '13 at 13:15
  • BTW, setting it to false apparently is an illegal value in my version of git. What version do you use for that? – jheld Mar 27 '13 at 21:44
  • @jheld Sorry - that should have been "nowarn" – Jesse Rusak Mar 27 '13 at 21:53
  • had the same kind of issue. nowarn fixed it. Thanks! – Thomas Aug 05 '14 at 18:37
0

UPDATE
I think this may be a duplicate of git whitespace woes
END UPDATE

Unless you've done some customization into your git post-commit hooks or to your git config core.whitespace settings (thanks for pointing that out jesse), git does not translate spaces to tabs or vice versa or anything like that. The changes are usually results of your environment/files and your merge activities.

Having dealt with this in various forms, my guess is that some of your peers are using tabs and some are using spaces. People will have flame wars all day long on whether you should use tabs or spaces, and depending on the day and language I hop sides. That's not something I will get into here.. However just about every rational participant in said war would agree that regardless of which you pick, you need to pick one and use it consistently throughout a project.

Most reasonable editors allow you to control whether tabs or spaces should be inserted, and I know XCode is no stranger to this.

I would suggest showing the whitespace or using briefly an editor which allows you to see the whitespace to see what the difference actually is. Seperately, after you correct a whole file you could also just use git diff -w -b to suppress white space changes. That said you should really figure out what the heck is causing your whitespace to go nuts on a rebase because that suggests to me most likely git is confused by mixed usages, and multiple people correcting it at multiple points with different resolutions.

Good luck to you, it's never easy, and someone is always unhappy when their cheese gets moved.

Community
  • 1
  • 1
UpAndAdam
  • 4,515
  • 3
  • 28
  • 46
  • For my knowledge, everyone who uses Xcode (or any editor for that matter) has it set to do tabs to spaces at 4 spaces a piece. In fact, in most cases the files in the changeset that I'm rebasing against are only being changed by me *on* the rebase. I've had a talk with one of my coworkers regarding the settings and hence why I came here because it doesn't seem obvious at this point. You certainly would be right if that wasn't the case, though! – jheld Mar 27 '13 at 13:18
  • Gotcha, sorry about that jheld. I'll see if I can dig up anything else. Is it definitely happening only on rebases as opposed to other merges? – UpAndAdam Mar 27 '13 at 15:40
  • In reference to Jesse's response, also look at setting tabwidth to 4 since default is 8. I've never used strip. I use trailing-space,space-before-tab,tab-in-indent – UpAndAdam Mar 27 '13 at 15:51
  • 2
    Also I'm assuming by everyone you meant people you knew and/or worked with :-) I've used and have worked with people who've used editors with VERY different settings. And my team's standard is 2 spaces – UpAndAdam Mar 27 '13 at 15:53
  • jheld take a look at athis, might be related to your whitespace woes. http://stackoverflow.com/questions/1316364/git-whitespace-woes I think the other issue might be using indent-with-non-tab that implies you are using tabs for indenting and not spaces. – UpAndAdam Mar 27 '13 at 16:08
  • The company policy is to use tabs=4 spaces in Xcode (and in other editors/IDEs) and certainly no one else has been having the trouble I do. I'll look into the definitions for the git tab settings. However, regarding the default of 8, I don't think it applies given that the "corrupt" changes have a smaller left margin, not right. 2 spaces? Yikes! You sound like my old OS teacher. – jheld Mar 27 '13 at 16:24
  • Also, to answer your question regarding merge over rebase...it seems to only occur on rebase, but what do I know? – jheld Mar 27 '13 at 16:30
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/27028/discussion-between-upandadam-and-jheld) – UpAndAdam Mar 27 '13 at 17:26
0

I don't know what about my git-config was the issue, but after clearing it out and re-doing my settings, the problem was fixed. I don't have my old git-config :( This occurred many months ago, but I thought I would express that this was not xcode related.

jheld
  • 148
  • 2
  • 8