0

For a few days, I have a problem with git.

Let's assume I have a branch "master". I create a branch "normal", I "git checkout normal", and then I change my code a bit.

If I "git checkout master", and then do a "git status", the changes I made on the branch normal are visible, while I'm on a completely different branch !

That's not the behavior I always had. I have to say I'm completely powerless right now. I don't know what happened.

Could you give me a hand ? I have git 2.3.3, and I'm on Manjaro Linux.

2
  • 1
    Did you commit your changes on normal branch before checking master out? Was git checkout master successful or did it report an error?
    – ge0rdi
    Mar 23, 2015 at 17:30
  • Nope, I did not commit my changes before I check master out. And yes, git checkout master was successful. And that's strange, because normally you can't checkout a branch if you didn't commit. I didn't have to 'git stash'.
    – Rififi
    Mar 23, 2015 at 17:58

1 Answer 1

0

You didn't commit your changes to normal branch. Only files in working directory were changed.

You can switch between Git branches even with changes in working directory. If there are no conflicts Git will show:

M       test.txt  
Switched to branch 'master'

This doesn't mean that those changes are now in master branch. They are simply in working directory. So you can now commit them to master (git commit -a) or check out normal and commit there.

If there is a conflict between your local changes and changes on branch you want to check out, Git will show an error:

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

In this case you need either to commit those changes, stash or completely discard in order to check out desired branch.

1
  • I didn"t know that, I thought the changes were in master too. Thanks.
    – Rififi
    Mar 24, 2015 at 8:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .