1

I tried to make a git branch testbranch, after this checkout git checkout testbranch. Then I edited a file, for example "README".

Now I tried to switch back to "master" branch, and it always makes a merge instead of only complaining that I have uncommitted files.

So why is this? I thought I would get an error like...

error: You have local changes to "X"; cannot switch branches.

So long and thank you for all the fish.

Daniel Hanrahan
  • 4,801
  • 7
  • 31
  • 44
user1735225
  • 113
  • 10
  • 1
    http://stackoverflow.com/questions/1304626/git-switch-branch-and-ignore-any-changes-without-committing could help here – VonC Oct 10 '12 at 14:59

2 Answers2

0

If your changes are compatible (are fast forward), git won't complain and will keep the modified version. Git will just assume that you've edited the file on the wrong branch and want to go back to the good one.

It's not a merge, though : git WILL comply if the file was both modified.

Merges can only be done at a commit-level, not at a file-level.

blue112
  • 52,634
  • 3
  • 45
  • 54
0

this issue occurs on me.

Actually, it's not a big deal.

Condition 1: git give you an error:

error: Your local changes to the following files would be overwritten by checkout:
    README
Please, commit your changes or stash them before you can switch branches.
Aborting

Condition 2: git gives you this:

M       README
Switched to branch 'master'

But, when does Condition 1 occur? or Condition 2?

Condition 1: there is a conflict of changing in README between master branch and testbranch.

Condition 2: it's ok for changing of README in master branch, so the changing occurs in master branch.

So no matter whether it is Condition 1 or 2, it's ok for you to use git because git is smart.

That's my point, i know you got it.

Good luck.

lijinma
  • 2,914
  • 1
  • 23
  • 22