When you're working with a team, there will be plenty of times when other people have made changes that you need to pull down to your local machine. In Eclipse, you can do this by either updating your project, or synchronizing with the Subversion server We'll show you both techniques, and talk a little about the differences between the two.
- [Instructor] With our last commit, we brazenly committed our changes without checking to see if anything had changed on the server. It did work and normally, Subversion is nice enough to tell you if there's a conflict at the time you make a commit but normally, you should pull down any changes from the server before you push your own changes up. In SVN terminology, the process of pulling down changes from the server is referred to as an update. This keeps your local working copy in sync with the server, so you can deal with conflicts and changes locally before you push them up. You should pretty much always do an update before you commit and I've always kind of wondered why it's not a part of the commit process in Eclipse by default, but it's not, it's separate.
So remember to update before you commit. You should also do an update if you haven't committed in a while to make sure that any changes on the server don't break your local code. And you should run update if you know something changed on the server or if you're highly suspicious that something might have changed. It doesn't really hurt to run an update, so you may as well make it a habit. To test the update process, we'll add a file in the repository outside of this Eclipse project. In Eclipse, choose the menu option Window, Perspective, Open Perspective, Other, and then choose the SVN Repository Exploring perspective.
Click OK. And this gives us a view of the entire repository. Expand the ProjectDonut folder. This is the one we're working on. And expand trunk, src, com, example, donut, and finally, click on collection. We'll add a file to this collection folder. To do that, right-click the collection folder and choose New, File. Click Browse and browse to your Exercise Files, 04_02, start folder.
There should be a file there called GiantBoxOfDonuts.java. Click on that file so it shows up in the File name box and Click Open. Now, type a commit comment. We're making a commit because we're adding a file to the repository. I'll type, "made a GiantBoxOfDonuts," and click OK. Now switch back to the Java perspective. You can do this by either clicking the Java icon over here on the right or by choosing Window, Perspective, Open Perspective, Java.
There are actually three different ways to update in Eclipse. You can run an update against the most current version, you can run an update against a specific revision, or you can synchronize with the server. These are all slightly different things and I'll show all three of them to you. First, we'll synchronize. Right-click the project and choose Team, Synchronize with Repository. This prompts us to switch to the Synchronize perspective in Eclipse. We'll click Yes. And the Synchronize perspective has a view on the left that shows us what the difference is between what's on the server and what we have locally.
If we expand src, com.example.donut.collection, we'll see this new GiantBoxOfDonuts file. At this point, nothing local has changed yet, so we haven't actually made an update. This view simply shows us what's different between what's on our machine and what's on the server. If you want to see the Subversion commit that added the file, you can right-click the file and choose Show History. I'll expand the History view and this shows you all the commits that changed that specific file, along with the commit comments and the name of the person who issued the commit.
In this case, it shows that we added the file and it shows the comment, "made a GiantBoxOfDonuts." I'll minimize this again and if we want to add this file from the synchronized view, just right-click the file and choose Update. This will pull the file down from the server and add it to our local project. I'm not going to do that just now because I want to show you the other ways of updating. Let's switch back to the Java perspective. The second way to perform an update is simply right-click the project in Eclipse and choose Team, Update.
This wouldn't prompt you to do anything. It would just pull the latest changes down from the server and then it's done. The last option for updating your project is by updating to a specific revision on the server. You can see that our local project is currently on Revision 10. That's the number right here next to the files. So any revision to this branch that's larger than 10 will be newer and that will contain the changes we need, depending on how many commits and updates you've done to your local Subversion server. Let's right-click the project again and choose Team, Update to Revision.
This gives us a dialog that lets us choose which revision we want to update to. It defaults to the Head Revision, which is the latest code changes on the server. We can also choose a revision from a specific date. I don't think I've ever used this option in real life but if you know a specific date or a time that a set of changes was made, you can use this option. If you're not using the Head Revision, you'll normally use the Revision option. If you choose this option and click the Browse button, it brings up a dialog with all the revisions for this project branch on the server.
We saw before that we're currently on Revision 10, so if we want the changes in Revision 11, we can choose that revision here. What's nice is you can see who made all the revisions and the commit comments at the bottom of the dialog. So pick the revision you want to update to. In this case, I want Revision 11 and click OK to use that revision for your update. When you click OK, it will complete the update and your local working copy of the code will be at that revision. So we've got three different options to choose from.
Which one should you use? Should you synchronize with repository update or update to revision? A lot of people prefer the synchronize option because it's the most visual and it lists all the files that are going to change. It also has the option of allowing you to update only specific files and folders if you want rather than getting all the changes at once. I tend to like Update to Revision because I like seeing everything from the perspective of what happened in each revision. And frankly, I know that I need to get all the changes eventually, so I may as well get them all at once instead of cherry-picking the specific files I want.
If you're a very trusting person and you always want the latest stuff regardless, it's easiest to use the one-step update option and do it all in a single click. That doesn't give you much information on what changed unless you go digging but a lot of times, that's not important. It's only important that you have the latest files, whatever they are.
- Trunks, tags, and branches
- Checkout, commits, and revisions
- Merging, locking, and working with a team
- TortoiseSVN on Windows
- SVN integration with Eclipse
- Connecting to a project
- Creating a new Java project in Eclipse
- Connecting to an existing Java project using Eclipse
- Dealing with projects that move to a new location
- Making changes and creating branches
- Tracking changes and dealing with conflicts
- Creating a release