Git switch branch problem
Hi folks,
i am currently evaluating IntelliJ Idea v.11.1.2, especially the Git-VCS integration.
I try to work with git branches. I can create a branch using the little drop down at the bottem right corner (clicking on "new branch"). After the branch has been created i edited a file and switched back to the master branch using the little drop down as well.
The VCS- console states a successfull checkout of the target branch and additionally merges the edited files. And thats my problem. Why are the changes merged in the other branch? Is that a bug? Ist there any configuration option to prevent immediate merging?
I dont want the files get merged when switching the branches.
Has anyone experiencd the same behaviour and found a solution to this?
Kind regards,
Sebastian
Please sign in to leave a comment.
Hello sebi,
Git keeps the state of working tree (when possible) when you checkout a branch.
So if you haven't committed this file, it just stays modified after checkout, because until you commit your changes, branches are not aware about them.
And merge doesn't happen in this case as well.
Many thanks for your quick reply.
So that means i have to commit all changes before switching the branch back.
Regards,
Sebastian
If you want these changes to be on this branch, then yes – you have to commit them.
You may want to read more about basics of working with branches and other Git structures, for example, in a very good book "Pro Git" (http://git-scm.com/book).
I find the behavior rather annoying.
Lets say I have a master, which i create a "Branch A" from. I make some changes to "Branch A", then go back to the master to fix something. The changes from branch a are not merged to the master. Who would want that to begin with?
I come from the Microsoft relm and VisualStudio did ask me if i want to "stack" the changes before switching to another branch but did not merge the changes to the target branch. So there is no out of the box setting that i can make to have that behaviour? I need to commit changes before switching branches to not have changes merged into the target branch?
Twanger you can use shelve feature:
https://www.jetbrains.com/help/idea/shelving-and-unshelving-changes.html
From your description it looks like you have some non-conflicting changes and git allows you to switch branches without shelving/stashing them (you can test this in command-line, if you made some changes, try to checkout a branch in command line and see what git says).
If there are changes that would conflict with a version on another branch then during checkout IDE will ask you whether you would like to shelve your uncommited changes or you want to do a force checkout.