Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EGit » Understanding Branches
Understanding Branches [message #998190] Wed, 09 January 2013 14:30 Go to next message
Dennis Putnam is currently offline Dennis PutnamFriend
Messages: 52
Registered: January 2012
Member
This is my first attempt to use branches and it is not behaving in a logical way to me. I created a new branch and made some changes. The unstaged changes look correct. I then switched back to the master branch. However, the changes I made still show up. I expected those changes to show in the branch and not show in the master. What am I missing about branches? TIA.
Re: Understanding Branches [message #998229 is a reply to message #998190] Wed, 09 January 2013 16:02 Go to previous messageGo to next message
Stefan Lay is currently offline Stefan LayFriend
Messages: 342
Registered: July 2009
Senior Member
Your changes will be referenced by a ("belong to") branch only after you have committed them while the branch is checked out.

If you want to switch back to master without keeping the changes in the working directory, you can just commit them before checking out master. When you switch back later on to your branch you'll get them again in the working directory. You can then still change the content of the commit with the "amend" feature.

Another possibility is to use the stash feature. But I find it more usable just to create a preliminary commit.
Re: Understanding Branches [message #998274 is a reply to message #998229] Wed, 09 January 2013 17:43 Go to previous messageGo to next message
Dennis Putnam is currently offline Dennis PutnamFriend
Messages: 52
Registered: January 2012
Member
Thanks for the reply. I will give that a try but it seems counter intuitive that a commit in the branch is needed to get the master to revert. Indeed, logically it seems the master should never show changes made in a branch until merged.
Re: Understanding Branches [message #998315 is a reply to message #998274] Wed, 09 January 2013 19:47 Go to previous messageGo to next message
R Shapiro is currently offline R ShapiroFriend
Messages: 386
Registered: June 2011
Senior Member
Although it might not be obvious at first, there's a good reason why un-staged changes remain when you switch branches. The use case goes like this:

You start working on a new task thinking that it's too small to bother making a new branch for this work. Then you start making changes and begin to realize your assumption was wrong, it really does need its own branch. Git's behavior makes this simple: just create and checkout the new branch and whatever changes you made so far are still available. I typically commit them immediately in the new branch.

This happens to me, and every developer I work with, pretty frequently. Developers are always under-estimating in this way.

The downside is what you ran into: if you have un-staged changes for some other reason and you decide to switch branches you should do something about those changes before the switch. But this is easy: if you have any reason at all to think you'll want them when you go back to the branch you're about to leave, commit them, as Stefan says; if you're certain you have no further use for them, replace them with the HEAD version.

Re: Understanding Branches [message #998326 is a reply to message #998315] Wed, 09 January 2013 20:06 Go to previous message
Dennis Putnam is currently offline Dennis PutnamFriend
Messages: 52
Registered: January 2012
Member
Thanks again. In that context it makes sense. Since I have not gotten that far yet I would never have thought of that possibility (until I did it to myself). Good to know.

[Updated on: Wed, 09 January 2013 20:07]

Report message to a moderator

Previous Topic:Mylyn Github task repository responds with connection refused
Next Topic:Missing Feature
Goto Forum:
  


Current Time: Thu Nov 27 16:31:21 GMT 2014

Powered by FUDForum. Page generated in 0.02693 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software