2

I have two branches in my local git repository: master and anotherbranch. When I switch from master to anotherbranch with git checkout anotherbranch and run git status I see modified files.

I undo these modifications with git reset HEAD and then git status does not display them. However when I switch to master and switch to the branch afterwards I see these modified files again.

Could you please explain what is going on?

Paŭlo Ebermann
  • 73,284
  • 20
  • 146
  • 210
Michael
  • 10,185
  • 12
  • 59
  • 110
  • Are the modified files tracked in both branches? Or only in one of them? – Amber Mar 08 '11 at 20:17
  • 1
    There's something you're not telling us, or not being clear about because the above situation, exactly as you've described, is impossible. Can you include in your question the actual output of your git commands? – Ben Collins Mar 08 '11 at 20:23
  • I would love to see how to recreate this in a step by step fashion. I tried to recreate it based on some assumptions I am making but could not. – Tone Mar 08 '11 at 21:18

3 Answers3

3

You wouldn't have autocrlf set to true, by any chance?
Because it can change your files on a checkout...

See the thread "core.autocrlf considered half-assed":

Back then, I was not a fan of the core.autocrlf support.
*But I have to admit that in the meantime, I turned into an outright un-fan of the feature. Not because its intent is wrong, but because its implementation is lousy.

Just try to git reset --hard or git stash when there are files with DOS line endings and when core.autocrlf is not false.

And then despair.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • @Mark: I have a long history with that setting... there are reason for having it set to true (http://stackoverflow.com/questions/2825428/why-should-i-use-core-autocrlf-true-in-git), but there are other ways: http://stackoverflow.com/questions/2332349/best-practices-for-cross-platform-git-config – VonC Mar 08 '11 at 21:47
  • I usually suggest to Windows users that they unset core.autocrlf and just use tools that are sophisticated enough to deal with different line endings. I admit that's cop out, but it rules out so many confusing problems. – Mark Longair Mar 10 '11 at 16:23
  • "Tools sophisticated enough to deal with different line endings" is pretty much any tool in existence. You'd have to try really hard to find a tool that doesn't. – Martijn Jul 31 '21 at 14:12
  • 1
    @Martijn I agree. This was not the case when I wrote this answer 10 years ago though. Even Windows Notepad did *not* support `\n` back then. Not before 2018: https://stackoverflow.com/a/50241693/6309. – VonC Jul 31 '21 at 14:18
  • Notepad was a notorious holdout, but I think very few people used git and also needed notepad support. – Martijn Aug 12 '21 at 14:23
1

If the items are not tracked in either branch, the files will show up in git status as untracked, and will survive across checkouts

Dan McClain
  • 11,780
  • 9
  • 47
  • 67
1

The git reset --hard will remove the modification from the index. Try with this additional argument it should be OK after that.

Artusamak
  • 2,470
  • 19
  • 19