Hack Attack: Using Subversion with TortoiseSVN

简介:

Last week I showed you how to set up a personal home Subversion server. For many of you, this was the first time you've gotten a close look at serious version control, so you may still be wondering what Subversion really does. On the other hand, if you get what it does, you still may be unsure how to use it.

This week I'm going to highlight some of the most basic, oft-used commands in Subversion with a little help from the very cool Subversion client for Windows, TortoiseSVN.

Subversion offers a lot of features, and if you really know your stuff, there's a lot more you can do with it than I'll be showing you today. But if you're just getting started with Subversion, this should have you upping your revision numbers in no time.

Since I've already covered creating and importing files into a repository last week, we'll jump right into checking out and editing a working copy of your Subversion repository.

Check out a new working copy

 

 

When you want to work with the files in a repository, the first thing you need to do is check out a working copy of your files into a new and empty folder. This can be any folder, anywhere you choose, as long as it's empty. So, for example, you could create a new folder on your desktop and name it "Project Checkout." To check out your project, right-click the folder and select SVN Checkout. Next you'll need to point TortoiseSVN to your repository.

If you set up Subversion with Apache, you can point it to your server from any computer. If not, you'll need to browse to your local Subversion repository. Click OK and you'll get your first checked out, working copy from Subversion.

Making and committing changes

Hack Attack: Using Subversion with TortoiseSVN

You'll notice that your working directory and the files inside of it all have little green check marks next to them. That means they're as fresh and unchanged as the second you checked them out of the repository. However, if you open up a file, make a few changes, and then save the file, you'll notice that the little green check mark has turned into a little red-and-white exclamation point. That means your working file is now different than the copy in the repository... which, of course, is good. After all, no point in version control if you aren't changing the files, right?

Once you decide that you're happy with whatever changes you've made and you want to add them to your repository, you can either right-click the changed file individually or just right-click your working directory and select SVN Commit. TortoiseSVN will open a dialog that lets you see what files have been changed and choose which will be included in the update. Once you click OK, the changed files should be pushed through to the repository and your revision number will have been upped by one.

 

 

Adding, deleting, and renaming files in the repository

Adding and removing files with TortoiseSVN is a breeze. If you want to add a file to your repository, it's really just a matter of one extra step beyond how you would normally add a file to a new directory. For example, if you create a new text file in your working directory, add it to the repository by right-clicking the file and selecting TortoiseSVN -> Add... TortoiseSVN will list the new file(s); you click OK and that's all there is to it. The file should display in Explorer with a little blue plus sign (+) beside it, and next time you run a commit, your new file will be added the the repository.

 

 

Deleting files is similarly easy - right-click your to-be-deleted file and select TortoiseSVN -> Delete. Again, next time you commit, the deleted file will be removed from your next revision. The same is true of renaming files - just go through TortoiseSVN rather than your normal Windows channels (right-click, TortoiseSVN -> Rename).

Revert is the new Undo

 

 

Any time you make a change to a file that you're not happy with, and you know that you want to go back to a previous version of a file, a quick Revert is the name of the game. For example, before I've committed any changes to my repository, I can right-click on any file and revert it to the state it was in when I first checked it out by selecting TortoiseSVN -> Revert... This can be hugely handy for those times you've accidentally destroyed the layout of your web page, for example, and have no idea how to get it back to where you started.

Browse your changes with Diff

If you want to dig down into the text of your files and see exactly where the files differ, TortoiseSVN has a great difference viewer called TortoiseMerge. To get an idea of how it works, make a few changes to a file, save the changes, and then right-click on your red-and-white exclamation-ed file and select TortoiseSVN -> Diff.

 

 

TortoiseSVN will now show you the difference between the base copy you checked out and the working copy you've currently got in your directory. If you don't like the changes you've made, you can merge the base version with the working copy line-by-line or in one big chunk. This is, for quite obvious reasons, one of my favorite features of Subversion/TortoiseSVN (aside from that whole obsessive revision-history business).

Roll back to previous revisions

If you want to undo the changes you made in a previous revision, the Show Log dialog is the place to go. Right-click your working copy folder (or working file), select TortoiseSVN -> Show Log. Find the revision you want to undo, then right-click it and select Revert Changes from this revision. TortoiseSVN will ask you if you want to revert all changes that were made in this revision; if you are, click Yes and any changes you made in the selected revision will be rolled back to their previous state, assuming you haven't made conflicting changes in the meantime.

Either way, the differences between your working copy and the copy you've chosen from the repository can be displayed and merged manually in the TortoiseMerge diff viewer by right-clicking the revision and selecting Compare with working copy.

More ways to use Subversion

Keep in mind that TortoiseSVN isn't the only way to interact with Subversion. If you love working from the command line, you can forget about TortoiseSVN altogether and work from there. If you're on a Mac, you can still install Subversion, and I've heard that a lot of people are happy using RapidSVN for a nice GUI. Last but not least, Eclipse has a great Subversion add-on called Subclipse, if you like working from an IDE.

If I've missed your favorite Subversion commands or uses, let us know about it in the comments or at tips at lifehacker.com.

Adam Pash is an associate editor for Lifehacker who takes comfort in the knowledge that he can always go back to a file from two weeks ago if he really messes something up. His special feature Hack Attack appears every Tuesday on Lifehacker. Subscribe to the Hack Attack RSS feed to get new installments in your newsreader.

 











本文转hackfreer51CTO博客,原文链接:http://blog.51cto.com/pnig0s1992/767886,如需转载请自行联系原作者

相关文章
|
安全 Shell Linux
靶机实战-vuluhub系列-Hack djinn:1 : walkthrough
靶机实战-vuluhub系列-Hack djinn:1 : walkthrough
靶机实战-vuluhub系列-Hack djinn:1 : walkthrough
TortoiseSVN的安装
TortoiseSVN的安装
100 0
TortoiseSVN的安装
|
开发工具 git Windows
|
关系型数据库 测试技术 Apache
|
关系型数据库 测试技术 Apache
|
关系型数据库 MySQL 数据库
|
Web App开发 .NET Shell