navigate site menu

Start learning with our library of video tutorials taught by experts. Get started

Fundamentals of Software Version Control
John Hersey

Fundamentals of Software Version Control

with Michael Lehman

 


This course is a gateway to learning software version control (SVC), process management, and collaboration techniques. Author Michael Lehman reviews the history of version control and demonstrates the fundamental concepts: check-in/checkout, forking, merging, commits, and distribution. The choice of an SVC system is critical to effectively managing and versioning the assets in a software development project (from source code, images, and compiled binaries to installation packages), so the course also surveys the solutions available. Michael examines Git, Perforce, Subversion, Mercurial, and Microsoft Team Foundation Server (TFS) in particular, describing the appropriate use, features, benefits, and optimal group size for each one.
Topics include:
  • Comparing centralized vs. distributed systems
  • Saving changes and tracking history
  • Using revert or rollback
  • Working with the GUI tools
  • Using IDE and shell integration
  • Installing different systems
  • Creating a repository
  • Tagging code
  • Branching and merging code
  • Selecting a software version control system that's right for you

show more

author
Michael Lehman
subject
Developer, Mobile Apps, Desktop Apps, Programming Foundations
software
Git , Mercurial , ALM/TFS , Perforce
level
Intermediate
duration
2h 55m
released
Nov 07, 2012

Share this course

Ready to join? get started


Keep up with news, tips, and latest courses.

submit Course details submit clicked more info

Please wait...

Search the closed captioning text for this course by entering the keyword you’d like to search, or browse the closed captioning text by selecting the chapter name below and choosing the video title you’d like to review.



Introduction
Welcome
00:04Hello, I'm Michael Lehman, and welcome to Fundamentals of Software Version Control.
00:09In this course we'll look at how Software Version Control tracks and maintains the history
00:13of your creative output as you work.
00:16I'll start by giving you an overview of the principles of Version Control and talking
00:20about key concepts and terminology used in tracking changes using software tools.
00:26Then we'll walk through how these concepts are implemented in five of the most popular
00:29version control systems: Subversion, Perforce, Team Foundation Server, Git, and Mercurial.
00:42We will be covering how these five products can help you work faster, be more confident,
00:47and sleep better, knowing that every stage of your work is automatically preserved.
00:52Now let's get started with Fundamentals of Software Version Control.
00:57
Collapse this transcript
What you should know before taking this course
00:00In order to make the most of this course, you should already know four key things:
00:05how to install applications, how to run applications on the command line, how to run applications
00:11using the Windows Desktop, and how to edit text files. With those four key skills, you'll
00:17be able to start using Software Version Control to automatically track your creative output.
00:22
Collapse this transcript
Using the exercise files
00:00As a member of the lynda.com online training library, or if you are watching this tutorial
00:05on a DVD-ROM, you have access to the exercise files used throughout this title.
00:10The Exercise Files folder contains four folders, each of which contains an archived version
00:15of the ending state of the Version Control Repository for chapters 1, 4, 7, and 8 which
00:22correspond to the initial Git demo, the Subversion chapter, the Git chapter, and the Mercurial chapter.
00:30Within each folder is one or more ZIP files and a readme.txt file explaining how to unzip
00:35the contents and connect them up with the corresponding software.
00:38There is also a file called Links.rtf which contains the URLs for downloading all the
00:45software used in this course and other helpful reference websites.
00:49Let's get started learning about Software Version Control.
00:54
Collapse this transcript
1. Overview of Software Version Control
Overview of software version control
00:01Hello, I am Michael Lehman, welcome to Fundamentals of Software Version Control.
00:06Version Control is the process of keeping track of your creative output as it evolves
00:10over the course of a project or product. It tracks what is changed,
00:16it tracks who changes it, and it tracks why it was changed.
00:24Keeping track of that evolution is vital.
00:26Maybe you are a developer, an artist, a writer, a composer, or a designer, you need it.
00:32Perhaps you write source code, build scripts, create images and icons or style sheets, you need it.
00:38Do you write novels or screenplays?
00:41Maybe you build spreadsheets or record music. You need it too.
00:45A team can use it, or you can use it for your own private projects because remembering what
00:51you've done and how it was done is a key part of creative success.
00:57Every good journey begins with a story. This is mine.
01:00A couple of months before I recorded this course, the main drive in my laptop died.
01:05It was one of those new high-speed solid-state drives, which crashes by losing everything
01:11with no hope of recovery.
01:12For me, the biggest loss was the files for this course.
01:16While I did have a manually-created backup, that ZIP only contained the latest versions.
01:22What really saved me was the contents of my cloud-based version control system.
01:26Not only did it have the latest and greatest, it contained all of the previous versions,
01:31the seven drafts of the script, the 14 versions with the PowerPoint slides, and the evolving table of contents.
01:38But not only did it have the content, most importantly, it contained the memory of what
01:42I learned in the process of building the course.
01:45After rebuilding my system disk, I synchronized my local directories with the data from the
01:49cloud, then I was back in business.
01:51Now, I told you that story so I can say this: everybody needs Version Control.
01:57So what's your story?
01:58Have you ever accidentally deleted the wrong file or had your hard drive crash?
02:03Have you ever made copies of an important directory as you worked only to wonder later,
02:06what's the difference between the working, the better, and the final, final with bug fix directory?
02:13Perhaps, more importantly, did you forget to make a copy of an important file before you
02:16started making changes and then need to get back to the original?
02:19Have you ever had to fix a bug in the bits you shipped 2 months ago and didn't have
02:23an easy way to get back to that exact state?
02:25More than likely, you answered yes to nearly all of these questions.
02:29If so, Version Control tools such as Subversion, Perforce, TFS, Git, and Mercurial will help
02:37you be more organized, safeguard your source code, and even get a better night's sleep. Sound good?
02:43So let's explore Version Control and see how easy it is to use and just exactly why it's
02:48priceless when it saves the day. Let's get started.
02:53
Collapse this transcript
Understanding version control concepts
00:00So what do you get from Version Control software?
00:03All Version Control systems provide four important features: peace of mind, every time you make
00:09an update and store it in source code control, your files are backed up; history, not only
00:15are the contents of your files backed up, the actual changes you made and your comments
00:19about why you made them are also captured so that when you come back 3 months from
00:23now, you can easily see what you changed, and you can remember exactly why you did it.
00:28This is because each change is accompanied by a short message which after a bit of practice,
00:33you will be the master of composing in a terse, pithy, brief, succinct, compact, and to the point style;
00:41friction-free undo, this means you can easily move back to a previous version.
00:45In some Version Control systems, this is done on a file-by-file basis, and in some the
00:50whole directory tree can be restored; and fearless experimentation, in addition to creating
00:55an automatic backup of your source code, you can also create a sandbox in which you can
00:59try out new features or make structural changes without worrying that you're breaking what already works.
01:05Version Control is even more important when working in a team providing three additional
01:09features: synchronization, when you store your changes in source control, your team
01:15members can easily update their copy of the source code from your changes; accountability,
01:20each time you store your changes, the Version Control system marks those changes with your
01:24user ID--this is crucial when working in a team environment as each time you grab changes
01:29made by someone else, you will be able to see who made the changes and why;
01:34and finally, conflict detection, when someone on your team makes a change that the Version
01:38Control system can't automatically merge with yours, the system will notify you and help
01:43you use differencing tools to resolve the changes.
01:47Without a tool like this, you might easily overwrite someone else's changes and lose a critical update.
01:52If you're not already using Version Control software, you're probably already doing some
01:56sort of change control by hand.
01:58You might be using Save As to make backups of individual files, duplicating and/or compressing
02:04directories to take snapshots and hopefully copying those backups to an external drive
02:08or a cloud-based system.
02:10The most time-consuming part of doing Version Control by hand is trying to figure out the
02:14difference between sets of changes.
02:16So you end up with directories like MoneyMaker-Working, MoneyMaker-ShipIt, and MoneyMaker-FinalFinalWithBugFixes
02:24and then trying to figure out what's the difference between those three.
02:28After you make the move to Version Control software, nearly everything is automatic.
02:32As you work, each new version is kept in a simple database-like system.
02:36Tracking changes from one version to another becomes the job of the Version Control system
02:40which can not only show you the changes, but it can help you remember why you made the
02:45change, because as I said before ,you're forced to add a comment each time you check in a
02:49change and make an update.
02:51You can also easily roll back to a specific version of either a single file or a whole set of files.
02:56And significant milestones can be marked by a process called tagging, or labeling.
03:01That means you can get back to that exact state of the entire product, which can be especially
03:05useful when you have to fix a bug in release 2.3.11 you made last December.
03:11So if you're ready to let Version Control software help you keep track of what you're
03:16doing and why you did it, let's get started.
03:20Before we roll up our sleeves and actually dig in, there are six key terms we need to
03:24define and these work across all different kinds of Version Control systems, but they
03:28are key to understanding the basic process, so the first one is repository.
03:34A Version Control system is an application or a set of applications that manage creating
03:37a repository, which is the name of the specialized database where your files and history are stored.
03:43In some systems, this is in an actual database, and in some systems this is done by creating
03:48a set of small change files which are identified by some identifier and managed by the software.
03:55The next is working set.
03:57Your files and folders can be organized into projects within the repository in a manner
04:01similar to how you manage files by keeping them in folders on your hard drive.
04:05The files on your hard drive, from the point of view of the Version Control software, are
04:09considered your working set.
04:11You change the files in the working set and then update the repository to reflect those updates,
04:17automatically creating a backup and denoting the purpose of the changes in a process--
04:21that's called add when you are adding new files or committing or checking in for existing files.
04:27Once you have added or updated files in the repository, you can easily revert your working
04:32set with any version of the data in the repository.
04:35If you're working by yourself, you can grab an older version. If you are working in a
04:39team, you can grab files that have been updated by your team members.
04:42That process is either called updating or checking out, and finally as we talked about
04:48before, you can mark the state of an entire project tree or an entire repository with
04:53an identifier called either a tag, or a label depending on the vendor, when significant
04:58events occur such as shipping a release or delivering it to a client.
05:02Next step, we are going to take a look at a Version Control system in action.
05:06First, we'll look at it conceptually, and then we'll open a command line and actually run
05:11a Version Control system so you can see it in action.
05:16
Collapse this transcript
Demo one: Getting started
00:00Let's take a look at Version Control in action.
00:02First, we'll look at it conceptually, and then we'll actually do it.
00:07So in this diagram, the repository where your files are kept is represented by the large
00:12right-facing arrow and contains the different versions of our files over time.
00:17So at 9 a.m., you create a repository for your new project.
00:21This creates the empty database to which you can add files to be tracked.
00:26Oftentimes this is done by a command called Init.
00:28At 10 o'clock you create myprog.c and add just the main function.
00:34Then you add it to your repository by checking it in. With each add or check in, Version Control
00:41systems ask you to compose a short message indicating why you are performing the check in.
00:45In this case, we'll say add myprog.c.
00:49Later on at 4 o'clock, you edit myprog.c again and add Func1 and save it back to your hard disk.
00:56This updates your working set, making it different from now what's stored in your repository,
01:00so you check in again.
01:02Now your repository has two versions of your file and two commit messages.
01:07Later that night, you're so excited about the app you're building and how easy it is to
01:11use Version Control to keep track of what you're doing,
01:13you add Func2 and check it in again at 1 a.m. What a day.
01:18Now let's look at this in a live version using Git.
01:22Okay, let's roll up our sleeves and actually use a live Version Control system.
01:27We're going to use Git since it's one of the most popular systems currently being used
01:31in the software development world, and it's easy to use from the command line on Windows, Macintosh, and Linux.
01:37We've installed Git by using one of the download links, and the Links.rtf file you'll find in
01:42the Exercise File directory.
01:44We're not going to go through the installation process here, we'll cover that in the chapter on Git.
01:49To begin, we'll open the Command window as I've done here, and the first thing we are
01:53going to do is validate the Git installation. We'll do that by typing git --version, and hitting Enter.
02:00What you should see is something like this, git version 1.7...whatever there is there
02:06in the rest of that line. That's going to vary, depending upon which build of Git you've actually
02:10chosen to download and install.
02:13Now that we've got Git installed correctly, we're going to proceed.
02:17So the first thing we need to do is make a directory called FSVC1, for Fundamentals of
02:21Software Version Control, and then we'll change to that directory.
02:30Once we're inside that directory, type git init to create the repository.
02:35Git doesn't store its changes in a single database file representing the repository,
02:40rather Git stores the data about your files and directories and all their history in a
02:44hidden directory named .git.
02:47To see that directory on Windows, we type dir /a, so there we can see the .git directory.
02:53We can verify that the repository is properly initialized by running git status.
02:58And as you can see, the message displays containing string to say On branch master,
03:04Initial commit, and nothing to commit.
03:07This means that your working set is in the same state as your repository. So now Step 2.
03:13We're going to create myprog.c and add it to the repository.
03:17On Windows we'll use Notepad, on OS X or Linux use our favorite Text Editor.
03:22So here we go, Notepad myprog.c.
03:25So first time we're going to create it, so we'll say yes, we want to create a new file,
03:30and now we're going to add Main. And then we're going to save it.
03:38Now our working set is different than the state of our repository.
03:42So every time you add new files, you have to tell Git to start tracking those files.
03:47You can do that in two stages or in one stage. In two stages, we're going to do it this way.
03:51The first time you type git add and then star, and it's going to add all the files it doesn't know about.
03:58And then if we run git status again, you can see it now knows, oh, I have a new file.
04:07In order to get the file into the repository, we're going to commit it, so we're going to
04:13type git commit -a -m, and then a message, add myprog.c.
04:22The first thing we're going to see is it didn't work because it said I don't know who you are.
04:27Every Version Control system needs to know who you are, so it can attribute all the changes
04:31that you make to you for your own purposes. That's pretty much you all the time, but when
04:37you're working in a team situation, that can be very crucial.
04:40So we're going to run these two commands that you see here on the screen.
04:42We're going to say git config --global user.email, and we're going to say you@example.com, and
04:55then we're going to say git config --global user.name, and we're going to say "lynda.com student".
05:05Now of course, you want to put in your own email address here and your own name or user ID,
05:10if you're working in a team.
05:12Whatever it is, you've all collectively agreed on whether you're going to use your email
05:16aliases or your actual name, but for the purposes of the course, we're going to use these strings
05:21for your own purposes.
05:22Make sure you put in your own email and your own name.
05:24All right, now that we've done this, we can go back and try our commit again.
05:30And in this case, the commit worked.
05:33You can see that it said one file changed and one insertion.
05:37So the string, add myprog.c is a sample of the kind of the message I mentioned before
05:42that you enter for each commit to indicate what you've changed.
05:46This message should be short and meaningful to either allow a future you or your fellow
05:50developers to understand why you made this commit.
05:54Note, on Windows the string should always be in double quotes.
05:58On OS X and Linux, it can be in single quotes, and we can verify that we've committed everything
06:03to the repository again by running git status, and you can see nothing to commit. That means
06:09we've added everything that we needed to.
06:12Now, even though we've only taken one short step, we can now ask the Version Control system
06:18to tell us the history, and in Git you say git log -p, and you can see this is a full detailed history.
06:27It says that Author: lynda.com student at you@exampleemail.com on the date that you
06:35do it, added this file, and then it actually runs a diff and shows you the difference between
06:40the previous version and the current version.
06:42Now in this particular case, the previous version was a new file, so what we see are the lines
06:47here in green which says we've added the main function.
06:52Now let's move on to make it change and see how versions are actually tracked.
06:56Let's reopen myprog.c and add Func1.
07:07And we'll save it back, and then once again as we did before, we'll commit it, so git commit -a -m "Add Func1 ()".
07:20And you can see we made one file change, and we made two insertions.
07:24So now let's once again see how that change is tracked by Git by once again running git log -p.
07:32So now you can see that we've got at the top of the screen here the definition that when
07:36we added Func1, the full diff, you can see the blank line and the line with Func1 in green there.
07:43And then you can see down below that there is the information about the previous commit
07:47we made where it says add myprog, and you can see at the bottom of the screen now there
07:50is a Colon with a flashing cursor next to it.
07:53When the list of changes is longer than a page, the paging mode is automatically invoked,
07:58so you need to hit the Spacebar until the Terminal window displays the word End and
08:02then type the letter Q to get back to your command prompt.
08:06So let's do the final step.
08:07I'll open up myprog.c one more time and add Func2.
08:21Once again, save our file and then do our commit again.
08:30In case you're wondering what that -a is on the command line, the -m is for the message,
08:34the -a is basically making it possible for you to do git commits in a single step.
08:40By default, you can do git commits in two steps, like we did, and we added the first
08:43file where you added and then subsequently commit it.
08:46Most of the time when I use Git, I just do it all at once so that I can say make all
08:52of my changes, and then I don't have to worry about whether I've added files, or I have
08:55changed files by putting that -a in the Git commit line.
08:59It automatically adds all the new files so that it handles it all as a single operation.
09:04So once again, we'll run git log -p, and we can see now that we've added Func2 and then
09:11we added Func1 and then we added myprog.c and finally we got to our end.
09:17Now you can see when you use git log -p, that is very verbose.
09:21There is a way of telling Git to get a shorter version of the history of the repository,
09:26so we do it like this.
09:27We say git log, now we give it some different arguments.
09:31In this case we say --oneline, because we want each revision to be on a single line, and
09:36we want to see all of them. So we say --all.
09:41And here we can see in reverse chronological order our three commits with their commit messages.
09:48The number you see in yellow there at the left is the ID, sometimes called the change
09:52set ID or the check in ID.
09:56Each different Version Control system does something slightly different, but there's
09:59always an ID that uniquely identifies the set of changes that you made.
10:04So now let's ask Git to show us the difference between our initial check in and the most recent check in.
10:10The way we do that is we actually use these IDs and use the git diff command.
10:15So we're going to say git diff, and we're going to put in the oldest one here, 6a3e577,
10:24now these numbers will be different for you.
10:25You'll have to look on your screen and see which GUIDs get created for this, and then we'll say 7555e83.
10:35And so you can see that it says in white that in the original one it only had the main function
10:42and in the most recent one, the Function1 and Function2 were added.
10:47When we get into we are actually doing delete. You'll see that delete show up as red lines.
10:51All right, well that's about 80% of everything you need to know to use Version Control.
10:57Let's look at the remaining 20% again conceptually and then we'll see it in action.
11:02
Collapse this transcript
Demo two: Handling the "oops"
00:00Picking up from where we left off before we'd created a repository and made a few check-ins,
00:04and you check things in at 1 o'clock in the morning, and you are happy.
00:08So the next day you open up myprog.c, and you realize that Func1, it's not exactly what you wanted.
00:17So you delete that, and as you are now well into the habit, you check in again.
00:21Then you get inspired and add Func3, and of course, check that in.
00:27After a bit of a reflection, you think maybe I could combine some of the functionality
00:30of Func3 into Func2.
00:33So you open up myprog.c, and again, start editing.
00:36Midway through that process, you say to yourself-- and this is the important part after saving
00:40myprog.c back to the disk, wiping out the previous version--oops, I guess that isn't going to work.
00:47Now in the days before your use of Version Control, you start sweating and wondering where you
00:51made a backup copy?
00:52Was it in that best-best final with bug fixes directory or in the best-best ship it directory?
00:58And you try to figure out how you could recover your work.
01:01But now that you've got Version Control on your side, you simply revert myprog.c back
01:05to the latest version of your repository, and you're ready to move forward again in
01:09moments, hero mode on. Now let's go see that on the command line.
01:15So once again we find ourselves here at the command line. As before, we're inside our fsvc1
01:21directory where our source code is there is our myprog.c.
01:25So let's open up myprog.c and delete Func1.
01:35Now we can run the git diff command and see what's the difference between what's in our
01:39working set and what's in the repository.
01:44Now in this case, we only have one file, so it's very easy in more sophisticated situations.
01:49You probably want to be able to specify either the file that you're working on or a subset
01:53of the directory; otherwise, you may end up with pages and pages and pages of this output.
01:58So we can see that the Func1 code has a minus sign at the beginning and is in red, indicating
02:03that the code was deleted.
02:04So let's check in this change, and then as you're beginning to trust Version Control,
02:16there is no need to look at the log at this point, so let's just go ahead and add Func3.
02:19So once again we'll come back and edit this, save it, and I will check that in.
02:38All right, and then we can run git log --oneline --all, see all of our changes, so we can see
02:45we've--if we read from the bottom--we added it.
02:47We added Func1, we added Func2, we deleted Func1, we added Func3.
02:52Now, we see our full list of commits.
02:55So now that we have all the numbers, we can run the git diff command between our check in
03:00number 3 Add Func2 and our most recent Add Func3.
03:05So we say git diff and the number there, 7555e83 and 4b8ed72, and you can see that it shows
03:18between those two different diversions we removed Func1, and we added Func3.
03:22So now let's once again edit myprog.c and come down here and delete Func3, and then we're
03:32actually going to save it, and you can see myprog.c no longer has Func3 in it, and we realize
03:40we didn't really want to do that.
03:42So in order to figure out exactly which version we want to restore--and in this case, we know
03:47it's the most recent one--in Git we can say git diff HEAD, and it shows us that the difference
03:54between the repository and the working set is that the working set has Func3 removed.
04:00So what we want to do is restore our working set to the latest state, to what was in the repository.
04:05So now we say git checkout myprog.c, and then if we type it out again, you can see
04:15Func3 is back in its full glory.
04:18And then we can see what the Version Control system thinks again, by typing git diff HEAD,
04:25and you can see that there is no difference between the working set now and the repository.
04:30And one other way--as we just ran git diff and saw that we didn't have any differences
04:36between our working set and our repository--
04:38another way to verify the repository is up to date with your working set is to say git status,
04:44and again, it will show nothing to commit.
04:48Now at this point, we're going to take this entire directory, including all the git hidden directory.
04:55Remember, we have this .git hidden directory, and if we just go take a quick look in there,
04:58there is a whole bunch of additional directories and files that keep track of all the versioning
05:04information, this is the repository information.
05:06For this particular thing, we're going to zip this entire thing and put it into the Exercise Files directory.
05:12If you then take that and unzip it in any directory that you want, and you come back
05:17to this top level, you can then say git log --oneline -all, and see the same thing that
05:26we just did here step by step in the course, and you can experiment with this particular
05:31repository to your heart's content, adding additional things, doing additional commits, practicing
05:37doing reverts in an environment where you know you have a repository that has some known
05:42working states that's compact enough to really understand, as opposed to somebody handing
05:47you a repository of 25 or 150 files with 200 commits already made.
05:53So next up, we'll look at a short history of Version Control and review the specific terminology
05:58that applies to all Version Control systems we'll be using in this course.
06:03
Collapse this transcript
2. Background of Software Version Control
The history of version control
00:00Before we begin using the modern Version Control Systems, a little bit of history is worth looking at.
00:06The first Version Control System was created in 1972 at Bell Labs where they developed UNIX.
00:12The first one was called SCCS.
00:14It was available only for UNIX and only worked with Source Code files.
00:19Ten years later the Revision Control System, or RCS, was developed, and it was the first
00:24cross-platform version control system, but once again, it was only for text files.
00:29Both SCCS and RCS only worked on the development system and were not for sharing code, as they
00:34only worked for a single user.
00:37The next wave of Version Control Software-- what we call Centralized Version Control--
00:42was developed starting in 1986.
00:45The Concurrent Versions System, or CVS, was the first one that had a central repository
00:50and was usable by multiple users.
00:53It was still file-focused and kept track of changes in individual files, as opposed to
00:57keeping track of changes in entire directory trees.
01:01Later on in the 1980s, along came Perforce, and it was widely used during the .com era.
01:07It's still the biggest repository used inside Google.
01:09In 2000, a new product called Subversion was created and supported non-text files, tracking
01:16directory structure changes, such as file renames and moves, and its transaction unit was the
01:21directory as opposed to an individual file.
01:24So you could check in an entire directory tree and check it out.
01:28In 2004, Microsoft created the Team Foundation Server to replace its aging Visual SourceSafe
01:34Version Control System, which was primarily a client server system.
01:38TFS comes with an MSDN subscription, which means it's fairly expensive.
01:42But it also has a TFS Express edition which is usable for up to I believe 5 users.
01:49TFS has tight Visual Studio integration.
01:52That means you can check in and check out right from inside Visual Studio.
01:56It supports not only source code control, but also has bug and work item tracking and
02:01features for doing automated testing.
02:03The next generation of source code control software is called Distributed Source Code Control.
02:08Distributed Source Code Control is different in that there's not a central server that
02:12everybody shares. Everybody shares their own individual repository and then can share
02:18their changes with a central server or share their changes with individual users.
02:24Distributed Source Code Control came about because of a change in licensing from a company called BitKeeper.
02:30Previously, they had a product which was used by Linus Torvalds and the kernel group on
02:35Linux that was called the Community Edition, and it was free.
02:39But in 2005, BitKeeper decided to make its entire product line commercial only, meaning
02:43you had to pay a fee for using it, and Linus decided that he wanted to make sure that everything
02:47around Linux was free, and so he created something called Git.
02:52It's broadly used in conjunction with something called GitHub which is an online cloud-based
02:57service which offers free hosting for open-source projects and also commercial hosting for private use.
03:04A competing product Mercurial was also created in 2005 in response to the same BitKeeper
03:10change and is also widely used in open source projects.
03:14That's a short history of Version Control from 1972 to 2012.
03:20These days, pretty much everybody uses one of five systems, Perforce, Subversion, or TFS
03:26if they want a centralized system, Git or Mercurial if they want a distributed system.
03:31And now that we have looked at the history, let's move on to looking at a little bit more
03:35details about the terminology that we need to understand, and a walk-through about how
03:41centralized and distributed systems work.
03:46
Collapse this transcript
Terminology
00:00Before we proceed into talking more about centralized and distributed version control,
00:04it's time to add a few more terms to our lexicon.
00:08Here is the terms we've already discussed: repository, the database where your changes
00:12are tracked; working set, your local files with potential changes not yet in the repository;
00:18add and check in, ways of getting data in to the repository; check-out and update, ways
00:24of getting data from the repository into your working set; and revert or rollback, ways
00:29of updating your working set to match specific versions of the repository.
00:35Distributed Repository Systems have the ability to take the contents of an entire repository,
00:39or the contents of a particular changeset, and send it to other users collaborating on the same project.
00:45When sending changes from one repository to another, you can do it via two methods, one
00:50is to use a method which uses HTTP or SSH to communicate the information to a remote
00:57server, the other is a way of extracting data from a repository to be able to send by email.
01:03So, when sending changes from one repository to another repository on a server, the terms
01:08are called push and pull.
01:10Push sends the changes from your repository to the server's repository, and pull gets
01:15the changes from the server and adds them to your local repository.
01:20As I said, this is almost often done via a server listing on HTTP or via SSH.
01:25If you wish to send your changes privately using email, you can do the same thing, but
01:29the terms are called import and export.
01:32You export from a repository which extracts the changes from your repository and puts
01:37them in a file that you can send as an attachment, and conversely, import allows you to take
01:41that file that somebody else sends you as an attachment and update your local repository.
01:47One of the most important features in a Version Control Software is the ability to name the
01:51specific state of a repository.
01:53This, as I said before, is called tagging or labeling.
01:56This allows you to say all the files that I have in this particular repository ,or all
02:00the files that I have in this project in a repository or in a well-known state, and I
02:05want to be able to get back to the state later.
02:07For example, when you ship version 1 before you begin to work on version 2, and 2 months
02:13later your customers says I need to make a change in version 1 right now and can't wait
02:17for version 2, you want to be able to get back to that exact state of version 1 so that
02:21you can make that update so that you can extract all the files that represent the state of
02:26your product or website or composition as a version 1, make some changes, and saves
02:32them back in a way that's separate from what the new stuff you're working on version 2.
02:37Sometimes when you're working on a project, you want to do some experiments, and we'll
02:40say what if I re-factor this particular function, or what if we redid the size of the website,
02:45or what if we decided to take out this chorus and add another bridge in the song?
02:50Version Control Software allows you to make a copy of your entire repository and work
02:54on this in a private sandbox. This is called branching or forking.
02:59Once you've done all your experimental work, you may decide that this is exactly what you
03:02want, and wish to add your changes back into the main portion of your source code.
03:07This is called merging.
03:08The thing that you branched from is oftentimes called the main branch or sometimes called the trunk.
03:14So what you want to do when you merge is integrate from your private branch back into the trunk
03:19or into the main branch.
03:22Sometimes you do this because your product is composed of a lot of pieces, and you want
03:25to be able to work on the individual pieces separately.
03:28For example, you might have an app that has an image processing component and an audio
03:32component, and two different developers work on each of these pieces.
03:36So, in this case, you would create two branches, one for the image processing developer to
03:41use, and one for the audio recording developer to use.
03:44Then when the image processing developer completes her work, she merges her future updates back
03:48into the main trunk.
03:50This is a special kind of merging called reverse integration.
03:54If the audio developer has also done a reverse integration and merged updates back into the
03:57main branch, the image processing developer may want to get those changes before proceeding
04:03on and making additional changes.
04:05So, she can grab the updates from the main branch in a process that's called forward
04:09integration, which is kind of like creating a new branch.
04:12It simply takes the changes from the main trunk and puts them into her private branch.
04:17And similarly, the audio developer can do the same thing with the image processing changes.
04:23We'll see this both conceptually and in action later in the course.
04:28
Collapse this transcript
Exploring centralized vs. distributed systems
00:00As mentioned in the section about history of Version Control, there are two different
00:04kinds of version control: Centralized, and Distributed.
00:08The workflow between these two different kinds are somewhat different, so I thought it would
00:11be worthwhile to go over the way in which these things are actually used from the point
00:16of view of a user using version control.
00:19So first, we'll talk about centralized version control.
00:22Typically, in centralized version control, a system admin creates the repository because
00:26the repository is always remote.
00:29Then you have your local working set, and you add or check in files to the remote repository,
00:35and you check out or revert files to update your working set.
00:39Similarly, another user using a centralized version control system will connect up to
00:43the remote repository and have a different working set.
00:47They will check out your files and updates that you've made and add their own, and this
00:52goes back and forth in this check in/check-out update loop as you work with Version Control.
00:58But in this case, in Centralized Version Control, everything is kept in the remote repository.
01:03Now, some benefits of that are that the system administrator can then keep track of
01:07updates, can manage backups, can do system rollbacks for all the developers at once.
01:15But it tends to be somewhat fragile, and it also tends to be problematic when you can't
01:20get access to the centralized server, if the server is down, if you're on an airplane,
01:25it becomes kind of cumbersome.
01:26So it depends on the magnitude of your project and the magnitude of your team, whether centralized
01:32version control is right for you, and we'll look back at that at the end of the course,
01:36looking at all the different Version Control Systems, and exploring how you can determine
01:40what's the right one to use for your particular project.
01:44Distributed Version Control works a little bit differently.
01:47Typically, you initialize the repository because the repository is on your local box.
01:53Similar to the Centralized Version Control, you still have a working set, and you add
01:56things and you update them.
01:58In addition, you can also have this optional remote repository, which is a way of backing things up.
02:04Now typically, people that use Git or Mercurial use a system like this, and they will use
02:09a hosted system like GitHub in order to be able to back up their local repository into
02:14the cloud, and that's done as we mentioned just before in terminology by using push and pull.
02:20Similarly, if that remote repository is not in the cloud but on another developer system,
02:26you would use import and export to send the data back and forth between the repositories.
02:32So that's a little bit of a look at the differences between centralized and distributed version control.
02:36Next, we are going to jump into all the concepts in more detail about getting things in, getting
02:42things out, how the process of history tracking works, and all of the information that you
02:47need to understand before we begin to look at specific version control implementations.
02:52
Collapse this transcript
3. Version Control Concepts
Getting files in and out of a repository
00:00The first thing you need to know to use Version Control is how to create either the entire
00:04repository or how to create a portion of the repository for the project you're working on.
00:09For a Centralized Version Control, most often the repository itself is created for you by
00:14your system administrator.
00:16With Distributed Version Control, you'll create the repository yourself at least on your local machine.
00:22And then you may synchronize it with another repository created on the server by an administrator.
00:26So you create the repository by using a command that's sometimes called initialize and sometimes called create.
00:33And what this does is create an empty space for you to put your files and directories
00:37in, as we did in our sample before where we simply created myprog.c and checked it in.
00:45If your files already exist, meaning you're adding an existing project to Version Control,
00:50you can use the Add feature of your Version Control Software to bulk add all the files
00:55and directories into your working set and then check them in.
00:59In Distributed Version Control, there's usually a concept between your file system and the
01:05repository that's called the staging area.
01:08So, when you actually do an add, the files go from your working set into the staging
01:13area and then from the staging area into the repository, because 99% of the time, the
01:20concept of using the staging area as two steps is more than you actually need, as we did in the previous demos.
01:28I did git commit -a -m and the -a meant add any files that are in the working set
01:36that aren't already in the repository automatically.
01:39So I could do that commit as a single step.
01:41Now of course, once you've got your files in, you want to get them back out in order to
01:46be able to work on them.
01:48And depending on the type of Version Control System you're using, whether it's Centralized
01:52or Distributed, you may be required to tell the Version Control System that you're going
01:56to start making changes to the files.
01:59Most centralized systems have the concept of check out.
02:02This means that you are telling the Version Control System that you are going to work on this file.
02:05So it will actually lock the file so other people cannot make changes until you check it back in.
02:10So, version Perforce and TFS allow you to specify which kinds of files, and which files
02:17require a lock on checkout, and which files don't.
02:21For example, you would typically require a lock on files that are non-textual, like images,
02:27or Zip files, or audio recordings, because the Version Control System can't easily detect
02:34the subtlety of a change in one portion of an image that you make and a change in another
02:38portion of an image that someone else makes and actually merge them together.
02:43So, if the files are not locked on checkout, then you might end up with conflicts when
02:48you check them back in.
02:49So, the reason that the centralized systems put the lock on there is to make sure that
02:54it's easy to make sure that reduces the number of conflicts and the number of problems you
02:59have checking in and merging.
03:00So for example, if Joe makes changes to a file, and then Arlene also makes changes to
03:04the same file, Joe can check his file, and then later when Arlene tries to check in, the
03:09server says that the changes conflict, and she ends up doing a manual differencing
03:14in order to resolve these things.
03:17TFS in particular has a feature called shelving which allows you to check out files and lock
03:23them, and then if you're not finished working on them before somebody else needs to make
03:27a change, you are going to actually take all the files you have checked out and put them
03:31in to what's called a shelf set, and essentially puts them up on the shelf so that the files
03:36can be unlocked and other people can work on it and then you can take your shelf set
03:40off the shelf, put it back into your working set, and do some more changes and then check
03:44in, because your changes don't necessarily conflict with what somebody else needed to do.
03:50But since the system actually locks the files, you may want to make sure that the person
03:54who needs to get in there can actually make those changes when they need to.
03:58Distributed Version Control Systems like Git and Mercurial specifically have made the concept
04:04of branching super lightweight.
04:06When you say git branch, it actually simply creates one extra file, and doesn't make literally
04:12a second copy of the entire directory in your working set.
04:17And when using Git and Mercurial in a team, the workflow is usually instead of locking
04:23the files, you actually branch the entire repository, make your changes, and then merge
04:27back in because it's such a lightweight process.
04:30We'll dig into more about that when we talk about branching and merging and when we demonstrate
04:35branching and merging in Mercurial and Git.
04:40
Collapse this transcript
Saving changes and tracking history
00:01Once you've got your files in, and you can get your files out, the typical workflow when using
00:05any Version Control System looks like this in your repository.
00:09At Time 1, you can see that there's a file in your repository that contains A, B, and C.
00:14Let's say you check it out and then you delete B and you add D.
00:18Now when you save your files back into the repository, use a command that's called commit, check in, or update.
00:24When you command the Version Control System to save your updated file, it will ask you
00:28for a short description of the changes you've made.
00:31This is oftentimes called a commit message, and this is a crucial part of the history of tracking information.
00:37The system will store the differences between the two different versions of the file, and
00:41you supply the reason.
00:42In some systems you can supply a single line, and in some systems you can actually supply
00:47not only a single line which is used in short displays, you can also provide an entire document
00:53that describes what it is. Reference bugs that are fixed by this have hyperlinks to
00:58websites that have appropriate references and so forth.
01:02Once you've added a file to Version Control and made a change and checked it back in,
01:06your Version Control System can now show you the history of that file.
01:09So, we can see here we have the file here at T1 with our initial commit, then we have
01:14two versions of file, and we add D, and now three versions of the file when we deleted B,
01:19and four versions of the file when we add E.
01:22Each item in the history will show you not only what is changed between one version and
01:26the other, it will also show you who made the changes, and what that person said about those changes.
01:31In this case, initial commit, adding D, deleting B, and so forth.
01:35It's important when creating commit or check in messages to be as descriptive as possible,
01:40because you may come back later and your memory may be a little fuzzy as to what you changed,
01:44or when you're working on a team, someone else may be reading your commit message
01:48and want to learn to understand what you did.
01:51Many systems allow you to create a one-line short commit message, and in certain systems,
01:55you can also create a longer descriptive message in which you can be more detailed
01:59in terms of what you've actually changed.
02:01You can add hyperlinks, you can add references to documents, you can add references to bug numbers.
02:07When you're using the Command Line tools, you can only add the short version, or if
02:11you leave the short version text off, the Command Line version of the tools will open
02:15up in the editor to allow you to put in both the short version, and the subsequent long
02:20version on subsequent lines.
02:21If you think back to our demo when I typed in git commit -a - and then put that string
02:27in quotes, if you leave the string off, it will open up in editor, showing you the information
02:32about what files have changed, and allowing you to enter in both the short and the long version,
02:37keeping track of the changes, automatically backing up your files, recording why something
02:43was changed, and who changed it is the essence of Version Control.
02:48
Collapse this transcript
Reverting to a prior version
00:01Sometimes when you make changes to a file, they turn out not to be what you want.
00:05You may open a file and accidentally delete too much and then save it back and realize,
00:09oh, I can't do any undo because I am already out of my editor.
00:13You may change the color palette of an image and then not remember what the original RGB values were.
00:18You may do some refactoring and then realize when you're done it's not the way you want
00:22to do it, and you want to start over.
00:24This is one of the places where Version Control systems can really help you out.
00:27So you've got your file in the repository at time T1, you would check it out or
00:32update it as necessary, and you begin to make some changes.
00:35You delete feature B and add feature D and then you realize that's not the way you want it.
00:41So with Version Control software, you can go back and say please overwrite the file in my
00:45working set with the most recently saved one, or even overwrite the file or the entire working
00:51set with the version from last Thursday.
00:53This is sometimes called reverting, and in some systems it's called rollback.
00:56Now, the key thing is that you have to identify the specific version you want to roll back to.
01:02Each time you commit or check in, the Version Control Software creates a changeset identifier.
01:08You can see here in the stack of files we have on the left that when we added feature C
01:12that created changeset number 23.
01:15So at anytime you can say, hey, I want to roll back to that particular changeset, and
01:20you tell it to revert to changeset 23, and now the working set has, well, it's at time 2,
01:26it has exactly what was in the file at the time you saved it as changeset 23.
01:32This is one of the big key benefits of using Version Control.
01:35You get the freedom to work quickly and the security of knowing the Version Control Software always has your back.
01:41
Collapse this transcript
Creating tags and labels
00:01While changeset identifiers are great for identifying individual changes, in some systems--
00:06particularly centralized ones--a changeset only reflects the files that were actually
00:11changed during a particular check in or commit.
00:14For example, here we have an initial commit and then a second commit where we added feature D.
00:19Sometimes you want to be able to identify the entire state of the repository at a particular
00:24point in time, such as a customer release or a major milestone of the project.
00:29Rather than writing down a cryptic changeset identifier, Version Control systems allow
00:33you to supply a human readable name describing the current state of the whole repository
00:37or project, in our case here, V1.0.
00:41This is called tagging in some systems and labeling in others.
00:44Now we can continue on and delete feature B and add feature E and then label it again version 1.1.
00:51I highly recommend that you take advantage of this on a regular basis, whether it's week
00:56by week, feature by feature, or release by release, because you'll find that the more
01:00you tag and label, the more your Version Control system could do for you.
01:05
Collapse this transcript
Branching and merging
00:00One of the most useful features of Software Version Control is called branching, but it's
00:05sometimes the most confusing.
00:07Some of the centralized systems make it somewhat complicated to merge two different branches
00:11together, so some people feel that branching is complex, but the branching part really
00:16couldn't be any easier.
00:19You start out with your main branch and your existing files, and you create a new branch,
00:25and now you have another set of identical files that you can make changes to.
00:29Because all branching means is that you're taking the current state of the repository
00:32and creating a new copy.
00:35In the new branch, as opposed to the main branch--which is also sometimes called the trunk--
00:38you can make any changes you want and they don't affect the product that is already working.
00:45This is a perfect sandbox in which you can experiment and you can refactor code.
00:49You can delete old unnecessary features and add brand-new ones.
00:54You really have full freedom to do anything you want to.
00:57In our example, a repository contains a file containing features A, B, and C.
01:02Once you branch you can see the main trunk still contains A, B, and C, and so does the branch.
01:07Now, at T2 we may delete C and add feature D.
01:13And this doesn't have anything to do with what we can do in the main branch, where we
01:16might, for example, add feature F.
01:19And back in the branch we might delete feature B now and add feature E.
01:23And this is all without changing our main production code.
01:28In distributed systems such as Git and Mercurial, branching is actually really, really easy
01:33and cheap because it only really creates a 40-byte file, simply creating a new GUID,
01:39indicating a new path of changes, that doesn't actually make a separate copy of the files.
01:45Hand in hand with branching is the reverse process, called merging.
01:49This allows you to take changes that you've made in a branch and add them back into the
01:53main trunk or into another branch. So let's take a look.
01:57We have our main branch, there is our main file, we'll create a new branch, as we did
02:02before, feature 1, and we'll take the copy and we'll add feature D.
02:08And now back in the main branch, we'll add feature F.
02:12And here in parallel, we're going to add feature E in the feature 1 branch.
02:17So as you do these changes, you might decide you like both sets of changes and want to combine them.
02:22In this case, we don't have any conflicting changes because we didn't delete anything, we just added.
02:28So now we ask our Version Control system to merge the two branches together, and now we
02:33end up with a new file 1, checked into the main branch with all the features from both
02:38the main branch and the feature branch.
02:41When there are conflicts, such as two changes in each branch that effectively did the same
02:45thing, for example, if we deleted feature B in both the main branch and the feature
02:511 branch, the Version Control Software sometimes can't tell exactly what you meant to do and
02:56so therefore it declares a merge conflict and requests that you resolve this manually.
03:02What happens is it brings up a differencing tool to allow you the human to look at the
03:06lines that have changed in context and make a decision of whether you want to take the
03:11version from the main branch or the version from your feature branch or both changes.
03:17On Windows, I highly recommend a tool called Beyond Compare to use as your differencing tool.
03:22On the Mac and Linux, there are many, many different tools that will allow you to do this effectively.
03:28One of the great benefits of Version Control Software beyond differencing is that not only
03:32will it require you to see the various changes that you've made, it will allow you to see
03:36the commit messages to determine the intent of the developer who made the changes so that
03:41you can understand how to merge the two branches together effectively.
03:46Branching and Merging are the two most powerful features in any Version Control system, and
03:50when used with care and thought, they can be the most powerful feature that you can
03:55use, because they allow you to experiment or work in parallel and then bring your work
03:59back together again at the end to create a completed product or project.
04:03So use branches whenever you want to be sure that the main branch or any other branch stays intact.
04:11
Collapse this transcript
Exploring workflow integration and continuous builds
00:01Some Version Control systems, such as Microsoft's Team Foundation Server, have what's called
00:06Integrated Workflow Item Tracking.
00:08This means you can have your testers associate a bug with a particular check in.
00:14So a developer who does coding checks in the source code, a tester does some testing and
00:19finds a bug, so they log the bug. In this case, it's called creating a work item.
00:24That work item now represents a particular issue that's going on in the software.
00:28It goes back to the developer who fixes the bug, and then when they commit their change
00:33to the Source Code Control System, the work item is also associated with that particular commit message
00:39so that when the tester receives the notification that, that work item has been updated, they
00:43not only have the commit message that the developer created, they also know exactly
00:48which bug which they created is associated with that, so they can verify that the bug
00:52has in fact been fixed.
00:54Here we can see an example. This is the Team Foundation Server Explorer inside Visual Studio,
01:00and here we have Work Items, and you can actually query for the Work Items that are associated
01:05with your particular user.
01:08Here we have a tester creating a New Work Item, and here the tester creates a new bug.
01:13In this case, Microsoft calls this an Issue, and they can fill in Priority and Status and
01:19a Description, add File Attachments, everything that a tester might want to be able to give
01:23to a developer to help them fix the bug.
01:26Another development technique that is often used in team scenarios is something called continuous build systems.
01:32This means that every time you make a change to the Source Code, the product is rebuilt
01:36to verify that your changes are compatible with all the other changes being made to the
01:40system before the changeset is recorded permanently in the repository.
01:45So the developer makes changes to the Source Code and does the check in and the system
01:49then runs a build to verify that the changes that were checked in built cleanly.
01:54You can even make sure that the build system actually runs unit tests to make sure that
01:58they test cleanly before actually committing the changes to the repository.
02:02I know that previous to this I said that the words check in and commit are equivalent,
02:07but in this particular scenario, the terms actually get split apart a little bit in order
02:12to be able to handle this multiphase committing process.
02:15So the developer does a check in and then the system does a build verification, and then
02:20once the build verification as passed, then the changes are actually committed to the repository.
02:25And here we can see in TFS a number of the different kinds of build quality gates that
02:30can be set up to determine when the code is actually committed.
02:34As you start to use Version Control, consider how it can work with the other tools you are
02:37already using, such as build servers and bug tracking systems, and you can create a more
02:42powerful tool out of the combination of these tools.
02:47
Collapse this transcript
Using graphical user interface (GUI) tools
00:01Almost all Version Control systems have at least four different ways of accessing the repository.
00:05First, as we've already seen is the command line.
00:09Most Version Control systems also have Window tools or GUI tools to access the repository.
00:15Some Version Control systems also offer integration into your favorite Integrated Development
00:19Environment, or IDE, such as Eclipse or Visual Studio.
00:23And many third-party tools allow integration into the file browser built into your operating
00:27systems, such as the Mac Finder or the Windows Explorer, and this is sometimes called shell integration.
00:33In this movie we'll look at the GUI tools, and in the next two movies we'll look at IDE
00:38integration and shell integration.
00:40Here we're going to look at five GUI tools available for the five Version Control products
00:45that we're going to be covering in subsequent chapters.
00:47There's not a GUI tool for Subversion for Windows, but there is a very nice GUI tool
00:53called Versions that's available on the Mac.
00:56Perforce has a Visual Client that works on both Windows and Mac, and they also have a
01:00web client which works on Mac and Linux.
01:03Microsoft's Team Foundation Server only works on Windows, but they have both the Team Explorer,
01:09which is a stand-alone GUI, and IDE integration, which we'll see in the next movie, which works with Visual Studio.
01:16If you use a hosted cloud provider such as GitHub, GitHub has a very nice GUI tool that
01:22allows you to work with teams, integrate issue tracking, and do code review, which is available here at github.com.
01:29For Mercurial, there's a nice visual tool available only for the Macintosh, which is called MacHg.
01:35It not only allows you to see your changesets and see inside the changesets, it also allows
01:40you to see a graph of the branching and merging so that you can visually understand how all
01:44the different changesets relate to one another.
01:47The GUI tools all include functionality that allow you to do bulk add, check in and check-out,
01:51reverting, branching and merging.
01:54They will also allow you to look at the repository and open up a file in the native file browser,
02:00such as you'll be able to right-click on the file and say Show in Finder or Show in Windows
02:05Explorer to actually open up the file system to correspond to the file that's in the Version
02:09Control system so that you can locate the actual files that are in your working set.
02:14As you can see, most visual tools provide advanced functionality that provides visual
02:19ways of performing the functionality that's specific to the Version Control system that they support.
02:24GUI tools can be really handy and can allow you to work really fast.
02:28If you're not comfortable with working on the command line, GUI tools provide a great alternative.
02:32If you are a command line junkie, you can do everything you want to from the command
02:36line and never have to touch a GUI tool.
02:41
Collapse this transcript
Integrating a version control system with an integrated development environment (IDE)
00:01Two of the most popular development environments, Microsoft's Visual Studio and Apple's Xcode
00:06have integration with Source Code Control built right into the IDE.
00:09In Xcode, Git is supported natively.
00:12In Visual Studio, Microsoft provides support for Team Foundation Server and many third
00:17parties provide support for Git Subversion, Perforce, and Mercurial.
00:22In many of these integrated development environments, the environment will automatically check files
00:25out for you when you begin modifying them and support check in, reverting, branching
00:31right within the IDE. So let's take a look at Visual Studio.
00:35Here we have a solution inside Visual Studio, a simple console application which has a
00:39main program and two separate features.
00:42I've gone ahead and created a project inside the Team Foundation Server on CodePlex and
00:46prepared to add this project to TFS.
00:50You can see the green plus signs right here and right here, next to each one of these
00:54things, indicating that an add is pending.
00:57But the code has not yet been checked into TFS, so let's go through that process.
01:01As you can see, it's not only here in the Source Code Control Explorer, but also over
01:06here in the Solution Explorer, the status of the files within the Version Control system are clearly indicated.
01:13So we'll come over here to the application, and we'll select Check In Pending Changes.
01:17First, it asks if you want to save your changes to make sure that the working set on disk
01:21is updated with the contents of the working set inside the application, so we'll save that.
01:26And now we have a Pending Changes tab over here now in the Team Explorer which has a
01:31place for our commit Comment.
01:33So we'll say Initial add of ConsoleApplication1.
01:39In more sophisticated things, you can actually associate related work items, decide exactly
01:44which changes you want.
01:45In this case, we're all set to go, we're going to click Check In.
01:49It asks us if we want to continue to check in 9 items, we'll say yes, and you can see now
01:53here it says Changeset 18686 successfully checked in.
01:58And now if we go over here and look in the Source Control Explorer, we'll see not only
02:02the folders, but we can actually see all of the files that are checked in.
02:07Here's the Properties folder, the App.config, and all of the files that we checked in.
02:10And if we come back to the Solution Explorer, we can now see this little lock icon, which
02:15means that these files are actually checked in.
02:18If we open up one of these in order to be able to do some editing, and we start typing,
02:22you can see over here in the Solution Explorer that it has a little red check mark, which
02:27means it's checked out to me.
02:29So that's the power of using a Version Control system integrated into the IDE is you don't
02:34have to go separately to your Version Control and think about the process of using Version
02:38Control while you're developing.
02:41While using a Version Control system in an IDE can be very powerful, don't forget there
02:45will be times when it fails, so always keep the command line reference handy.
02:50
Collapse this transcript
Examining shell integration
00:01We've looked at command line interfaces for Version Control, GUI interfaces for Version
00:05Control, IDE integration for Version Control, and finally the last way you can access Version
00:09Control is through a process called shell integration.
00:13This means that instead of just looking at the project file inside your IDE, you can
00:17actually look at the file in directory tree inside the Windows Explorer or the Macintosh
00:21Finder, or their equivalent on Linux, and actually look at the files in your working set where
00:26they live and interact with Version Control there.
00:29That allows you to add files, check files in, check files out, revert, all from right
00:34inside whatever the shell is that you're currently using.
00:37It can show you which files are up to date, which files are checked out, which files have
00:41pending changes, sometimes even which files have conflicts.
00:45The way they do this is by providing context menus so that you go to a file or a directory
00:50and right-click, and you'll see a series of context menus that allow you to check in and check out.
00:55They also have visual status indicators, such as green dots for files that are checked in
01:00and red check marks for files that are checked out and so forth.
01:03So let's take a look at the shell integrations available for Windows and for Macintosh for
01:07the five Source Code Control providers we're looking at in this course.
01:11First, for Windows there is a product called TortoiseSVN.
01:15This is a Windows Explorer extension for using Subversion with Windows.
01:20Perforce provides a product called the Perforce Plug-in for Windows Explorer that adds a Perforce
01:25menu to the standard Explorer context menu in Windows.
01:30For Team Foundation Server, Microsoft provides the Team Foundation Server Power Tools.
01:35While this is not part of the released Visual Studio product, it is something that is kept
01:40up to date with every release of Visual Studio and provides, not only Windows Explorer integration,
01:45but provides a number of additional facilities.
01:47If you're using TFS, I highly recommend getting the Team Foundation Server Power Tools.
01:52For Git, there is an open-source project over here on code.google.com called TortoiseGit
01:58that provides something similar to TortoiseSVN but for Git.
02:01As you can see here in the Context menu, you can Pull and Fetch and Push and Show the
02:07logs and Resolve, Revert. Everything that you can do on the command line, you can do
02:11from this Context menu.
02:13And the final integration for Windows is TortoiseHG, which is again, Tortoise for Mercurial, and
02:20you can see here it allows you to Add Files and Revert Files.
02:23And here you can see an example of the kinds of icons that are enhanced when using one
02:27of these shell extensions.
02:28Here you can see files that are checked in, files that still need to be added, files that have a conflict.
02:35Similarly, for the Macintosh there is a product here called SCPlugin, which is Subversion.
02:42They call it here a file-icon badging and commands from Finder. Essentially, it creates
02:46a context menu in the Finder that has Subversion commands on it.
02:51Similarly, DeltaWalker is an equivalent functionality for Git that does Finder extensions.
02:58And over here in Bitbucket, this Mercurial Finder Integration project is relatively new,
03:03but someone is in the process of trying to provide the Mercurial functionality as a Finder integration.
03:10So we've looked at the four different ways that you can interact within your Version
03:12Control software, there is the command line, there is stand-alone GUI tools, there is IDE
03:18integration, and finally there is shell integration that allows you to add context menus to the
03:23Macintosh Finder or the Windows Explorer.
03:28
Collapse this transcript
Looking at forward and reverse integration
00:01The last set of advanced features we're going to cover are called forward integration and reverse integration.
00:06These are a process that you use with branching and merging.
00:09Consider you might have a product, as we talked about before, but it has two separate features
00:14that can be worked on by two different developers independently.
00:17If these two different features interact, as your developers each work in their private
00:21branch, they may want to from time to time check their changes into the main branch so
00:25the other developer can get them, and they may also want to get changes from the main
00:29branch back into their private branch to continue working.
00:32So let's take a look and see how that works.
00:34So we start out with our main branch, and we create two separate branches, one for each
00:38developer, feature 1 branch, and feature 2 branch.
00:42Initially, they both contain the same set of information that's in the main branch,
00:45and now they begin to diverge individually.
00:48In the feature 1 branch, developer number one adds feature D and then decides because
00:54developer number 2 may need to be able to use feature D, they check it back into the
00:57main branch in a process that's called reverse integration.
01:01Now, the reason this is more than just a merge is that the first developer is going to continue
01:06to work in their feature 1 branch as opposed to moving back to the main branch.
01:10Now, developer number two continues to work in their own private branch here in feature 2
01:15branch and adds feature E.
01:17When they're done, they check that in, again, through another process called reverse integration.
01:23In order for developer 1 to continue to keep working in their private branch and yet still
01:28take advantage of the code for feature E, they go through a process called forward integration,
01:32which allows them to take changes from the main branch and put them back into their private branch.
01:37Now, this is slightly different than creating just a new branch.
01:41Similarly, developer number 2 might do a forward integration back into their private branch
01:45in order to pick up feature D.
01:47In the end, when you get to the final point where the product is shipped, feature 2 branch,
01:52feature 1 branch, and the main branch all have exactly the same code, because they've
01:56all been integrated together through a series of reverse integrations and forward integrations.
02:01What's interesting about this is when you look at really, really large development projects,
02:06this is the way they work.
02:07For example, inside Microsoft, Windows is done this way, Visual Studio is done this way.
02:13In Visual Studio there are teams of hundreds of developers.
02:16One team works on Visual Basic, one team works on Visual C#, one team works on the Editor,
02:22another team works on the XAML visual designer, and all of those teams work independently,
02:27going through numerous forward and reverse integrations over the course of creating a
02:31new version of Visual Studio, only to end up with all of the teams having their branches
02:36be equal to the final shipping product.
02:41
Collapse this transcript
4. Subversion
Installation and setup
00:00All right. Let's roll up our sleeves and dig into Subversion.
00:04Subversion, as we mentioned earlier is a centralized Version Control system.
00:09This means there's one repository shared by multiple people if multiple people are working on a project.
00:15You can also use Subversion in a local installation, which is what we're going to do here, but
00:21that repository is not something which you can export like you can with Git and Mercurial.
00:26It's really a single repository that's used by you. And if you set up a server to be able
00:32to access that, other people could also access it.
00:36There are both free and commercial options for subversion.
00:39As I said for free, you can download and install a local version, you can also use it with
00:44Microsoft's CodePlex website, which is free for open-source projects, and there's a 45-day
00:50free trial of a commercial version at codespaces.com.
00:55All these links as with all other links in the course are also going to be in the Links.rtf
01:00file inside the Exercise Files directory.
01:03So first up, let's install the local version of Subversion, which is abbreviated SVN on
01:09the command line, and I'll be calling it SVN from time to time throughout the rest of this chapter.
01:15The Subversion install is a straightforward MSI-based installation.
01:18So let's fire it up.
01:20Now, usually where I install subversion is in the C:\svn directory, it makes it much
01:26easier rather than putting it in Program Files, because then you have a directory name with
01:30spaces, and if you're running on a 64-bit version of Windows, you end up with the space,
01:36parenthesis, x86, so it's easy to just to install it here in C:\svn. All right.
01:43So we've got Subversion installed.
01:46Let's open up a command box and make sure that we've got all the paths and environment variables set correctly.
01:52So we type svn --version, and you should see something like this, and the most recent version
02:00as we recorded this course was 1.7.6.
02:03Now, it's possible if you have some applications open, that a reboot may be required, but in
02:08our case, everything was closed down, so we can proceed on.
02:13Once this installation is complete, there's one additional step.
02:16All of the environment variables are set with one notable exception, SVN_EDITOR.
02:22If we look at our environment variables, we can see when we look in the esses, that particular
02:26environment variable is not set.
02:28This editor is invoked whenever a commit message is required, and you don't supply one on the command line.
02:34This is particularly useful when you want to do multi-line commit messages.
02:38To set this easily, you can say set SVN_EDITOR= Notepad, or whatever other editor you prefer to use,
02:47as long this is on your path, and if we type set again, we can see now that that environment variable is set.
02:55If you want to set this permanently, come to the Start menu, right-click on Computer,
02:59select Properties, select Advanced system settings, select Environment Variables, and then click
03:05New in here and add it into your Environment Variables.
03:09Note that after you've done this, it doesn't actually set that environment variable for
03:13any existing open command prompts, so you have to close your command prompt and open it up again.
03:18For this course, we're simply going to use it, and we're setting it on the command line.
03:24That's the installation of Subversion. We've got our editor set.
03:27Let's move on to start creating a repository and a project.
03:32
Collapse this transcript
Creating a repository and a project
00:00Now that we've got Subversion installed, let's create a repository and then a project inside that repository.
00:07Creating a repository in Subversion is easy, use the svnadmin command.
00:11So we're going to say svnadmin create c:\svn\r1, r1 is the name of the repository you want to create.
00:21You don't have to create it inside the SVN directory, but it's a convenient way to make
00:25it easy to back up all the repositories by simply backing up the SVN directory.
00:30Next step, we need to create a project.
00:33Project setup in Subversion can appear to be somewhat complex, but once you have learned
00:36how to do it, it's the same every time.
00:39There is a set of conventions that are commonly used so that if you move from one group to
00:44another that's using some version, you'll see the same kind of pattern being used because
00:49it makes it easy to do branches and tags and keep track of which is the trunk.
00:53So, I always name my projects, as you know XXX-YYY, where XXX is the name of the repository
01:01and YYY is the name of the project.
01:03So then I know just by being in the project directory where everything is located.
01:07So we'll create the project by saying svn mkdir and then create the URI and then use
01:14the URI for our repository r1/r1-p1 and then we'll create a commit message for that, "Create project p1".
01:25All right. Our project is now there.
01:28Now as I mentioned, using SVN is the convention regarding how the project directories are set up.
01:34This involves creating three specific directories, one called branches, one called tags, and one called trunk.
01:40If you have an existing directory of source code, what I would suggest you do is go there,
01:45create these three directories, and then move the original contents of your directory into
01:49the trunk subdirectory before doing the import.
01:52Since we don't have an existing directory, we're going to create this directory structure
01:56and import it into Subversion.
01:58So we're going to go into the temp directory, and we're going to make a directory called
02:03r1-p1, and then we're going to go in there and create the subdirectories, so it should look like that.
02:16Now, we're going to import that into Subversion by using svn import, and in this case, I'm not
02:23going to put the -m because I'm going to show you how the editor's invocation works
02:27because we did that set SVN_EDITOR=notepad , and so here it's going to open up Notepad.
02:33You'll see that there is a line that says --This line, and those below, will be ignored--.
02:37That shows you the status of all the things you're doing.
02:41Any line or lines you put before that are your commit message.
02:44So we're going to put Import structure of project p1 and then when we save that and
02:52quit Notepad, it automatically adds it to the Subversion repository.
02:58Now in our case, since we did it from a temporary directory, we can go ahead and go back to
03:02the root and delete that temporary directory.
03:06And now finally, we want to change directory to the place where we want the working set to live.
03:11In this case, I'm going to do it at the root of the C drive, but you may want to put it
03:15inside of a directory called work or div, or wherever you keep your source code.
03:19Note that this is different than your original directory if you had files in it.
03:23You can put it in that same place, but remember your original directory with files is not
03:28part of Subversion, it's not being tracked for source code control,
03:31so you need to create a new directory using Subversion that has not only your files, but
03:36also some metadata that allows Subversion to track your changes.
03:40So in our case, we're going to svn co--now CO is short for checkout. Subversion has long
03:47and short versions of many of the commands. In this case, CO stands for checkout.
03:52Another one I'll use quite a bit is CI, which is short for check in, which is actually short
03:58for the Subversion commit command.
04:00So we're going to check out our svn repository 1, repository 1, project 1, and what this is
04:07going to do is not only create a C:\r1-p1 directory, it's also going to collect all
04:14the data from the repository, including any files we had in the trunk directory and put
04:19them in there and tell Subversion to start tracking them.
04:21So now if we go and cd to r1-p1, you can see that there is our subdirectory structure that we wanted to have.
04:30Now in order to be able to ask the Subversion if it's really tracking this, we can say svn log -v,
04:35and now we can see the entire log.
04:40First, you'll see revision 2 says that changed these paths, and so revision 1, we actually
04:45created the subdirectory for project p1.
04:49So that's all there is to creating a repository and a project.
04:53You can easily create additional projects inside this repository, you simply skip the
04:58first SVN admin command and then just start with the svn mkdir command for creating your additional projects.
05:06Let's move on to adding some files in there and do some check ins and check outs.
05:11
Collapse this transcript
Working with check-in, checkout, and revert
00:00We've got a repository and a project set up. Let's add a file and check it in.
00:05Our working set is in the trunk directory, so first we change to that directory and
00:10then we'll create the file and we're going to put in the following code.
00:15The content is from the new project haiku error messages page.
00:19We're going to pick one that's happened to all of us before we started using Version Control.
00:22With searching comes loss and the presence of absence, My Novel not found. All right.
00:50So we save it, and now we're going to add it to the repository.
00:54But before we add it to the repository, let's ask Subversion what's the status of the files in this directory.
01:01You can see it doesn't know what to do with f1.c because we have to tell it to add it to the repository.
01:06So to add it, we type svn add f1.c, and then if we run svn status again, you can see we
01:14have a pending add for our file that's not yet been checked in.
01:17So to check it in, we're going to commit it, we're going to type svn commit, and we're
01:21going to put a commit message on the command line here, Add f1.c.
01:26Now, if we ask svn the status of this project, we can see that all the files are checked in.
01:30But if we want to look at the log, we can only see the message that says, we imported the structure.
01:37You might wonder what happened to my check in?
01:39Well, with svn, in order to get the log up to date, you need to run svn update command.
01:45Now when we look at the log, you can see both the initial creation of the directory and the addition of f1.c.
01:53Now, if you look at the beginning of each of the lines in the log, here, and here, you
01:58can see the letter R followed by a number.
02:01In Subversion, this is the revision number or changeset ID.
02:05So let's use Notepad to open up f1.c, and then we'll change the words "My Novel" to
02:11the word "Website". Now we'll save the file.
02:15Now we're going to check it in again, but this time we'll use the editor feature to
02:18add our commit message.
02:19SVN has many shortcuts for its commands, and in this case we'll use svn ci, which is a shortcut for commit.
02:27As you saw before, CO is used for check-out, so they had to use some other set of letters,
02:32instead of using CO for commit, they used CU, as in check in.
02:37So we type this and Notepad opens.
02:40You did remember to set your SVN_EDITOR environment variable right?
02:45If not, you got an error message at this point.
02:47So set that environment variable now and rerun this command in order to follow along from this state.
02:53So in the editor that appears, in our case it was Notepad, you might have set it up to
02:57use your own favorite editor. We're going to add a multi-line message, so Change "My Novel" to Website.
03:08Change message to better reflect product features.
03:13And as we save this and exit, we can once again run svn update, and then run svn log
03:22and see here's our Import structure, our Add f1.c, and our multi-line change message.
03:30Now, when you're trying to hunt for A revision number for some of the commands we're about
03:34to use, this could get very, very long with all of the change messages.
03:38So the log file command has a way of allowing you to see just the revision numbers and the times.
03:43So if you type svn log -q, you get a listing that just has one line for each revision or
03:49changeset that's been checked in.
03:51So now let's make another change, and then we'll roll it back.
03:55So once again, we're going to open up f1.c, and we're going to change Website to Webpage.
04:04In order to see the differences between our most recent version in our working set, we
04:07can use the svn diff command, and you can see it shows that we're currently on revision 4
04:13in the repository. This is our working copy, and here this is essentially the line we deleted,
04:19website not found, and this is the line we added or essentially changed to Web page not found.
04:24Now, svn diff shows the differences between all the files in the working set and the repository.
04:33So if we want to only see the differences between one file in the current repository,
04:37we can say svn diff f1.c.
04:39Now in our case, it's going to be exactly the same, because we only have one file.
04:44You can also ask for the differences between the working set and a specific version.
04:48So for example, if we say svn diff and ask for the distance between this and revision 3,
04:53you can see that in revision 3 we had "My Novel" and currently we have Webpage. All right.
05:00Now, let's roll back to the topmost revision, which is our most recent commit.
05:05So we say svn revert and revert this file.
05:10Now it's reverted. Now when we type it out, you can see we're back to Website.
05:15Finally, you can also revert to any revision, not just the top revision by using the update command.
05:21So let's go svn update, back to revision 3, and when we type it out again, we're back to "My Novel".
05:31Note, none of your changes in the repository have been lost. Everything is all still there.
05:38It's just the basic workflow of being able to update the working set.
05:41So for example, we could update back to revision 4 and get back to Website, and now we're back to Website.
05:50Remember, none of your changes in the repository have been lost. You're just updating your working set.
05:55So that's the basic workflow of check in, check out, and revert.
06:00You'll also want to look at the Subversion documentation to see how to delete files,
06:04how to rename files, and how to move files within directories and create other directories.
06:09All right. Now, let's move on to tagging.
06:14
Collapse this transcript
Tagging
00:00As we learned earlier, tagging or labeling is a key feature of version control.
00:05It allows you to tag a complete set of files so that you can get back to a known state
00:11which will allows you, for example, to fix a bug in a released version while you're working
00:15on the next version. Tagging in SVN is really easy.
00:19We'll just move up one directory to the parent and then tell SVN to make a copy, svn copy
00:25from trunk to the tags directory, and we'll call it v1.
00:30Now if we run the status command, you can see the svn thinks we want to create a v1
00:35directory inside of tags and add f1c to that.
00:40Our tagging is not complete as we still have to commit the tag to the repository.
00:48So if we do svn update and svn log, we can see now that we have here at the top create tag for version 1.
00:58And for the future if we do svn log and pipe it into more, we'll be able to stop it so
01:04that it doesn't scroll off the top of the screen.
01:06So here we can see the entire revision 5 where we're creating the tag for version 1.
01:11Now go inside the tags directory, and we'll go inside v1, and there is our f1.c.
01:18All right, that's how easy it is to do tagging.
01:20Now, any time you need to make updates, you'll come back to this directory and be able to
01:25make your changes right here.
01:27And now this is separate from what's in your trunk directory, so those two things now are completely independent.
01:32
Collapse this transcript
Branching and merging
00:00The last major piece of functionality we need to explore is branching and merging.
00:04In SVN, it's done much like tagging.
00:08We create the branch from the common parent directory, the one containing the trunk, tags
00:11and branches by using svn copy.
00:14So let's go back up to the parent directory, make sure we're in the right place, there
00:18we can see branches, tags, and trunk, and then we'll execute the following command, svn copy
00:23trunk branches\b1, our branches are going to be called b1.
00:30Once again, you can see this is pending, it hasn't actually been created yet.
00:36So we do a commit again and create branch b1.
00:48Scroll off to the top of the screen, once again log more.
00:53There we see it, created branch b1 that's revision 6.
00:57Now you notice that SVN doesn't make a distinction between your branches and the trunk in terms
01:03of its revision numbers.
01:05All updates go to the same list of revisions, each with its own revision number.
01:09This is because the revision number represents revision of the entire repository, not just of a single file.
01:16So, to work with the branch we have to go into branches b1 and make an update.
01:24So in this branch we'll add a method called feature1, No more available space, Look to the cloud,
01:38Your hard drive is full. All right, and then we'll save this.
01:45Now if we ask SVN for the status, you can see that we've modified file f1.c and the
01:53branches b1 directory.
01:55If we switch back to the trunk directory and ask SVN status, you can see it shows no changes,
02:03so it's keeping these independently.
02:05So now we'll switch back to the branch, and we commit.
02:16And then I'll update, and there is a shortcut for SVN updates, just svn up.
02:24And there we can see Branch b1: Added feature 1.
02:28You might note that I put the words branch b1 in front of the commit message.
02:32That's because subversion doesn't track for you which branch changes are made in, so therefore
02:39a convention that's often used is include the branch name in the update message.
02:44So, let's quit this and talk about merging.
02:50If you want to continue to work in a branch for an extended period or time, you want to
02:53do a forward integration from the trunk from time to time.
02:57That time varies based on how active the trunk changes are if somebody is actually working there.
03:02Usually, you do that weekly.
03:03You do that so that your branch doesn't get too far out of date with changes in other
03:08areas of software that you're not working on.
03:11But in our case, the trunk is just fine so we're going to do just a reverse integration
03:15from our branch and merge our changes from the branch into the trunk.
03:19So first, we're going to go look at the log to see which range of changes are correspond to our branch.
03:25So in our case, you can see we created our branch at revision 6, now we added our update at revision 7.
03:32So first we have to get back to the root directory of our project and then we're going to use
03:38the svn merge Command, so we tell it to merge all the versions we have done in the branch.
03:43So svn merge -r6:7 branches\b1 trunk.
03:53As before note that this does not actually record those changes in the repository, we
03:58still have to check those in.
04:00But now you can see instead of M for modified, it has U for updated and from merging, and
04:05it shows you that it's merging and recorded a merge info for that.
04:09So now we're going to say svn ci Merged changes from branch\b1 into trunk, and there we can
04:25see revision 8 we have merged changes form branches b1 into trunk.
04:29And our new feature is now in the trunk, and we can prove that by going into the trunk
04:34and typing out f1.c.
04:36And you can see that we have both our original change and the feature.
04:40Okay, that's the basics of branching and merging.
04:44Obviously, you can get a lot more complicated than that, and you can find yourself in situations
04:48where there are conflicts, and you'll have to manage them manually using differencing tools.
04:53But it just shows you it's not hard to do branches, and it's not difficult to merge
04:57the changes back together if you properly coordinate what it is you're doing.
05:02Typically, there is going to be two different kinds of branches. You're going to do either
05:06a fix branch or a feature branch.
05:09What we did here was a feature branch, but sometimes you might just take the current
05:13state of your product, make a branch in order to a fix, and then merge that fix back into
05:18the product while someone else continues on working on the main branch to do future things.
05:23All right, we're done with subversion in the command-line, let's move on to taking a look
05:27at subversion in shell integration using TortoiseSVN.
05:32
Collapse this transcript
Working with GUI clients and IDE integration
00:00For the final part of our exploration of Subversion, we'll use the TortoiseSVN Shell integration tool.
00:07TortoiseSVN is free, and you can find the link to download the installer in the Links.rtf
00:13file in the Exercise File directory.
00:15Here we have it on our desktop, double-click on it.
00:20TortoiseSVN, as I said, is a shell extension, meaning there isn't going to be an icon that
00:25you run it from. It runs all of the time, anytime you have a Windows Explorer window open.
00:31Remember, as I said, TortoiseSVN is free, but the developers like to have your appreciation
00:36and support. You can donate to them by clicking on the Donate button there.
00:40All right, we have it installed.
00:43In order to get the icons in the Shell integration fully operational, after you've installed
00:48the TortoiseSVN tool, you have to do a reboot.
00:52So let's go, go to the Computer, go here, and we'll see now that there is a nice icon
00:57right here on our project folder.
01:00With TortoiseSVN, we can perform almost all subversion functions right from inside the
01:03Windows Explorer using the right-click Context menu.
01:07Note that this does slow down the display of the Context menu just a little bit, as
01:11it queries the repository behind the scenes every time you right-click.
01:15But the power you get in exchange is substantial.
01:18So let's go ahead and open up this directory, and we'll open up the trunk directory and look around.
01:24The first thing you can see is that our file f1.c has a nice check mark icon inside of a green circle.
01:31This means that TortoiseSVN has queried the repository and shows us that the status of
01:36this file is checked in and up to date. So, let's open it up and make one more change.
01:42We're going to add ellipses to he end of the word cloud and save it.
01:49Note now that the icon on f1.c has changed to an exclamation point inside a red circle,
01:55indicating the file has uncommitted changes.
01:57To commit, we simply right-click again, come down here and select SVN Commit, and you can
02:03see that TortoiseSVN has its own built-in Commit Editor.
02:07And it doesn't use the value of SVN underbar editor the environment variable we set before,
02:13so let's add a message and then we'll save it.
02:18It automatically runs the commit now and shows us the log at that particular spot.
02:23Once we click OK here, you notice the icon returns back to the white check mark inside
02:29of the green circle.
02:31If we explore the TortoiseSVN fly-out menu, you can see that you can perform Diffs, Show
02:36the Log, Browse the whole Repository, perform Updates, Deletes, Locks and even Branch and Merge.
02:43As our last exploration of this, however, let's select the Blame command and see it was made
02:46changes to our files.
02:50You can see that the Blame dialog opens, and you can select a range of revision you wish
02:53to examine and get some diff options.
02:55In our case, let's just click OK and see what we get.
02:59So you can see that in this case, of course I made all of the changes here, but you can
03:03see the revision number in each line over here, and you can see the section here indicates
03:09this is the most recent set of changes.
03:12So you can see exactly what it is that's happening with the file in its current state in the repository.
03:18One last note, if you remember back to the command line section, all of the URIs I used
03:23to describe where the repository was or the form file:///c:/SVN and so forth.
03:32Those are URIs, which means you're using a local repository.
03:36If you are using a remote repository, you would substitute either an http or https URI or
03:44even one that says SSH depending on the protocol and the location point of the remote repository
03:50that you're actually using. So, that's our tour around subversion.
03:54There is many more features but these are the essential things you need to know to use subversion day to day.
04:03
Collapse this transcript
5. Perforce
Installation and setup
00:00All right, let's take a look at Perforce.
00:03Perforce is a centralized version control system with a new distributed add-on called Git Fusion.
00:09We're only going to locate the centralized version because Git Fusion actually requires
00:13a separate server in order to run it.
00:15Whether it's virtualized or real, it allows you to use Git as a front end for Perforce.
00:21For up to 20 users or 20 workspaces, Perforce is free.
00:24And of course then there are commercial licenses which I believe are sold on a per seat basis.
00:30There's also a cloud-based version that you can use in the trial basis.
00:34And you can find that to link you see here on the screen.
00:36This link will also live in the Links.rtf file in the exercise files folder. And also
00:42here's the link to download the local version that gives you that up to 20 users 20 workspaces for free.
00:51So let's move on and install the Perforce Server and the Perforce client.
00:56
Collapse this transcript
Working with check-in, checkout, and revert
00:00Okay, we've got Perforce and all of its tools installed, but unlike some of the other tools
00:05we're using in this course, Perforce works directly with the file system as opposed to
00:10having the GUI client be integrated and automatically create folders and files from inside that client.
00:16So what we need to do now is open the Windows Explorer and switch to our Work directory.
00:24And inside here, we're going to create a directory within a workspace called p1.
00:31Now if we switch back to the Perforce client, you don't see it yet, but once we click this,
00:35Refresh, there is our folder p1.
00:38Perforce manages files, not folders, meaning we have to actually create a file in order
00:43to get Perforce to add this folder to our workspace.
00:47So we'll come back here, we'll go inside p1, and we'll right-click and say New Text File,
00:52and we'll put in ReadMe.txt.
00:56Doesn't have to have anything in it. In our case, let's come back to Perforce, refresh
01:01again, and now we open up p1, you can see ReadMe.txt.
01:06You can notice that this has blank icon that means that Perforce recognizes that that's not in the depot.
01:12The way we add it to the depot is we right-click on it, and we say Mark for Add.
01:17Perforce can have a whole bunch of pending changes lists. You can have something you're
01:21working on over here and something you're working on over there and the default change list.
01:26For everything we're doing in the course, we're going to use the default change list, so I'm
01:29just going to click Don't show this dialog again.
01:32But you can create multiple change lists if you want to be working on certain things and
01:36hold back changes and not check them in until you're ready.
01:40But in our case, we're going to be checking in the changes every time we make a change.
01:44All right, now that we've marked that for add, we can see a few things.
01:50First of all, down here at the bottom, you can see the fact that this in fact has been marked for add.
01:57This is actually the command-line version of that command, and you can see what I meant
02:00about the fact that there is all these complicated flags in order to simply just add a file to the repository.
02:07You can also see over here in the Details pane where the actual file is, where it's going
02:12to go on the repository, which revision it is the date and time, the type of the file
02:18and which kind of file Perforce thinks it is.
02:21Perforce's file types have to do, whether they're text or binary, so that knows which kinds of
02:25different thing to do when doing differencing and merging.
02:29So we've got our file, it's got now a text icon, and it's got a plus, meaning it's marked for add.
02:35And so let's go ahead and add that in to the repository, and we'll say Submit.
02:41And this is the Changelist Submit dialog we're going to say Create folder p1 with ReadMe.
02:49And we'll say Submit, and now you can see we have a nice little green dot there indicating
02:55that it's up to date in the repository, and our working set has the latest version.
03:01Now let's add some code and understand the lifecycle working with Perforce.
03:05The content we're going to use is from the new project's Haiku Error Messages page.
03:09These aren't actual Haikus, but they kind of feel like one.
03:12We're going to pick one that's happened to us all before we started using version control.
03:16Again, we have to create files by using the Windows File Explorer or our Text Editor, not Perforce.
03:24So we come back here, we'll right-click once again and say New Text Document, and I'm going
03:29to call this thing f1.c.
03:34And Windows is very kind and asks us if we want to make sure we got the right kind of
03:37file, because it will decide to open Visual Studio when we double-click on this to edit
03:43it, so we're going to go ahead and do that.
03:48In this case, f1.c is going to say main () printf With searching comes loss, and the
04:04presence of absence, My Novel\" not found. With Visual Studio we can simply
04:21click Save All, and that saves the file, and now we can switch back to Perforce and add
04:28it to the repository, come back to our workspace, refresh it once again, now we can see the file.
04:37Once again we have a plain icon, we will right-click, Mark for Add, and then we'll Submit, and we'll
04:46say Initial Commit of f1.c.
04:53Once again, we can see all the command line operations down here in the log.
04:57Now, to see the history of what we've done so far, we can right-click on our p1 folder
05:03in the workspace and select Folder History.
05:06And now you can see the list of Changelists we've done with this folder.
05:10Changelist 1 we created the p1 folder by adding the read me ReadMe.
05:14Changelist 2, we did an initial commit of p1.
05:18Unlike SVN and Git and Mercurial, Perforce is a locking version control system, so before
05:23we can edit this we have to check it out.
05:25You notice we have a green dot but we don't have anything that tells us we can edit it.
05:30So with Perforce you have to right-click here and say Check Out.
05:34Now you can also do Check Out and Open if you want to open with the default tools, so
05:39we'll just do that, Check Out and Open.
05:41Once again, it opens Visual Studio. Now let's change My Novel to a more modern error message.
05:47We'll say Website not found.
05:49And we'll save it, and we'll Exit Visual Studio, and now you can see it shows here in the History
05:56that f1.c is pending a change, and let's save that file and check it in again.
06:02So once again, we'll do a Submit, and we'll say Change My Novel to Website and submit it.
06:14Now we might want to look at the history of the file, so what we can do now is we can
06:18come down here and say File History, and over here, since we have the History window open,
06:28we can see that here's the file history of the file.
06:31So if we select these two lines together and say Diff Selected, it'll open up Diff tool
06:38and show us the changes we've just made.
06:44One of the cool tools that Perforce has is something called the Time-lapse View.
06:48Now right now it's only going to show two different versions, but here is version 1,
06:54there's version 2, and if we had more-- which we'll see later--we'll actually be able to
06:58see the file as it changes over time.
07:02All right, now we're going to make one more change.
07:04Again, we're going to Check Out and Open, and we're going to change Website to Webpage,
07:11Save it and Exit Visual Studio.
07:13And now again, we're going to Diff this against what they call the Have Revision, which is
07:18the Head Revision, and you can see what's in the depot here. This is the depot side
07:23with the purple triangle as Website, and what we haven't checked in is web page.
07:28But remember we have saved it, so now we're going to do is we're going to revert.
07:33We're going to right-click here and Revert.
07:36Now the Revert dialog says what are we going to revert.
07:39In this case, we're going to Revert our edit.
07:42We right-click here, and now if we go and Diff this against the Have version, you're
07:47going to see that it says Website in both cases because we've updated our workspace
07:52with the content that we had originally.
07:55All right, now we reverted to a particular version.
08:01Now if we want to actually revert to a specific version, for example, we can come back here
08:05to the initial version and right-click on here and say Rollback to Revision.
08:12This is going to allow us to roll back to anything that we want to.
08:16So for example, we could roll back to the previous version, or we can roll back to a
08:19specific revision, we can roll back to a specific changelist, a Date and a Time or a Label.
08:25So you've got a very flexible manipulation of files within Perforce.
08:30So in this case, we're going to roll back to Revision 1, and they give you a predefined
08:37changelist description. We're going to run it, and now we're going just kind of come
08:41down here and Open this up and see that we're back to My Novel.
08:48Now remember, all the different versions are still inside the repository. You haven't lost anything.
08:54So for example, if we come back here and we do another rollback, we can roll back to
09:04the Changelist, and we can browse for the Changelist and go all the way back to Change
09:09My Novel to Website and submit that.
09:16And now when we Open the file you can see we're back to Website.
09:23So that's the basic workflow for using check-ins and check-outs and reversion and rollback in Perforce.
09:28Now let's move on to tagging, which is called labeling in Perforce, and see how we can use that.
09:33
Collapse this transcript
Tagging
00:00Tagging, or creating a human readable label for a current state of a repository in Perforce
00:05is called Labeling, and it's really easy.
00:08We'll just go to our folder p1, right-click, go down to the Label menu, and up comes the Label dialog.
00:15In this case we'll put in our Label, we'll say it's v1, and we'll automatically apply
00:20the label to the file revisions of the things inside Work\p1 at the latest revision and click Label.
00:26And it says This label doesn't exist. Create it?
00:30Yep, that's what we want.
00:32Now labels are suitable for rollbacks, and we can see that by starting the rollback process
00:36here for this file, and if we dropdown Rollback file to: we can pick label, and when we browse.
00:45There is our v1 label.
00:46So this is the way in which you switch between different versions when you want to roll back
00:50and make a change and then roll forward toward to where you were to continue on working.
00:55And that's it for labeling in Perforce. It's really that easy.
00:59So we're not going to actually roll back anything because we're already at the most recent version.
01:03So let's move on to Branching and Merging in perforce.
01:08
Collapse this transcript
Branching and merging
00:00The last major piece of functionality we're going to do with Perforce is branching and merging.
00:04You branch by right-clicking on your folder, in this case, and selecting Branch.
00:13Now Perforce does branching in the depot, not with the physical folders, but within folders within the depot.
00:20So what we're going to do is decide where we want to put our branch folder.
00:25And because it's not a physical folder, it's not a good idea to put your branch inside
00:30the folder with your main branch.
00:32You want to put it within the depot perhaps as a peer of your main branch.
00:36So here's our source, depot/p1, and our target isn't going to be depot/p1, say b1 here.
00:44We're actually we're going to put it up here. We're going to say -branch1/, and after we do the
00:50branch we said automatically submit after branching the files.
00:53We're going to go take a look at the depot, and when we refresh it we see that we now have two
00:59different sets of folders in our depot.
01:03And these files are different, we haven't created two separate folders in our workspace,
01:09but we just have two separate folders in our depot.
01:12So if we want to edit the file in the branch, we can go here Check Out and Open, and now
01:19we'll add a new feature, feature1, No more available space, Look to the cloud,
01:34Your hard drive is full, and we'll Save and Exit Visual Studio.
01:49Again, you can see the files in the repository. The file has the check box, meaning we've checked
01:55it out into the default changelist, and now we're going to go ahead and submit that.
01:59Now we're going to say Added feature 1, and now it's all set up, and we're back in that
02:08particular branch's changelist.
02:11If you continue to work in a branch for an extended period of time ,you want to do a forward
02:15integration from the mainline to your branch from time to time.
02:19Remember, a forward integration means copying changes from the main into your private branch
02:24so that your branch doesn't get too far out of date for those portions of your code which
02:28you are not working on in the branch.
02:30That means if you're working on a team and other people, they are making changes, you may want
02:34to take their changes as you're continuing to work on your features to make sure that
02:38both your features don't conflict with theirs and your features may depend upon working
02:43with their features before you can check back in.
02:45In our case, we're just going to do a reverse integration and merge the changes from our
02:49branch back into the trunk.
02:52The way we do that is we right-click on the branch folder, and we select Merge/Integrate.
03:00Now the Source of our merge is our branch.
03:02The target of our merge is going to be back to p1.
03:08Now we're going to go ahead and open up the Options here in order to click this, Automatically
03:13resolve files after merging. That way it's a very simple merge process.
03:18If you want it to do the merge and then have to run the Merge tool to make that you have
03:23checked exactly what's being merged, you can do that by not checking that box.
03:28But in this case, we're going to click Merge, and you'll see now that says this file has
03:34been merged, and it's been marked for integrate but the change has not yet been saved back to the repository.
03:40So we'll open up our changelist Pending window, and you see now we have Merging depot branch back to p1.
03:46And we'll right-click on that and say Submit.
03:50It gives us an automatic message here. We could create a more sophisticated one, but we'll submit that.
03:55And if we now come back here and say Open f1, you can see we have both our main and our feature.
04:02So the Merge has been successful, we've taken things from the branch1 and inserted them
04:08back into the main trunk, and so now everything is back together again.
04:13And that's Branching and Merging in Perforce.
04:14We're going to take one quick peek at one more thing before we leave this chapter, and
04:20that is just note that installing the Perforce GUI also does give you a show integration
04:25menu that allows you to do additional things.
04:28Once you become much more experienced in working with Perforce, this can save you some time in the future.
04:35And that's it for version control with Perforce.
04:40
Collapse this transcript
6. Microsoft Team Foundation Server (TFS)
Installation and setup
00:00Time to roll up our sleeves and dig into Microsoft Team Foundation Server.
00:05Microsoft Team Foundation Server is a centralized revision control system. This means that there
00:09is a server with an actual database that holds your repository and all of your projects.
00:15There are two versions. There is the full on TFS, which requires an installation of full
00:21SQL Server and has to be run on a Windows Server Installation, and that's great for
00:25enterprises and large groups.
00:28There's also a free for open-source hosted version at codeplex.com.
00:34And just recently, Microsoft introduced the Team Foundation Server Express Edition 2012,
00:38another one of those great names which is free for up to five users.
00:43It's something you can download and install, and it requires installation of SQL Server
00:48Express, but that's something that you get with Visual Studio 2010 and Visual Studio 2012.
00:53There is also a number of commercial companies which host TFS installations, including discount
01:00ASP which has a 30 days free for five users and then fairly reasonable fees for hosting a TFS installation.
01:07For this chapter we're going to install the Team Foundation Server Express 2012, abbreviated TFS.
01:14You can just as easily work through this chapter using the free TFS server on codeplex or your
01:19own full installation of TFS.
01:22The link of installation binaries and the Links.rtf file in the Exercise's directory.
01:27The installation of Team Foundation Server Express 2012 is straightforward; however, you
01:33may run into an issue with SQL Server permissions if you've had a previous version of Visual
01:38Studio or SQL Server installed on your development machine.
01:41There's a link in the Links.rtf file to a page where you can download a script to fix this issue.
01:47The installation of TFS Express is essentially hands-off and takes about 30 minutes, so
01:52we're not going to do a full walk-through.
01:54Also, while some TFS functionality can be done from the command line, the real TFS experience
02:00is within Visual Studio.
02:02So we'll be doing everything for TFS using the Visual Studio GUI.
02:06So let's fire up Visual Studio and make sure that we've got Team Foundation Server properly installed.
02:13To validate that you've got TFS installed you can see that you've got the TEAM menu.
02:18So we selected TEAM menu and select Connect to Team Foundation Server.
02:23Here you can see this is a list of team project collections and projects.
02:27We don't have any servers installed yet, so we're going to click the Servers button, then
02:31we're going to click Add, then we're going to enter the name of the machine on which
02:35the TFS Server is installed. In our case here, it's car-booth-06-pc.
02:42By default, TFS works on a TFS PATH and a Port Number of 8080 and over HTTP.
02:49Your administrator may have additional settings for you here, different Port Numbers, different Paths, use of HTTPS.
02:57Check and ask your administrator for the URL of your Team Foundation Server if you're using
03:01something other than the Team Foundation Server Express.
03:05If you're using codeplex, go to the Source Code Control Tab and select the Source Code
03:10Control, connect information, and it will give you an HTTP URL and the User ID and Password
03:17that you'll need to connect to the TFS instance on codeplex.
03:20So over here, we're just going to click OK and then we're going to click Close, and now
03:26you can see we've got Team Foundation Server, and it has a default collection, so from that
03:31point of view, we're good to go.
03:33So we'll click Connect, and now we see the Team Explorer - Home.
03:37So that's it for our TFS setup. Now let's move on to creating a team project and then
03:42creating some projects to check in to our TFS instance.
03:47
Collapse this transcript
Creating a repository and a project
00:01All right, let's get ready to create some projects inside the TFS.
00:04There is only one repository in TFS, and that's on a machine-by-machine basis.
00:09The way to create projects inside TFS is first you have to create a team project and then
00:13you create folders which hold your individual projects and branches.
00:18So first, we are going to create a team project, click there, and we will give it a name so
00:22we will call it TFS1 and description of our project is TFS Team Project for Fundamentals
00:31of Software Version Control.
00:34We will click Next and with TFS you always have to pick a Process Template.
00:40TFS comes out of the box with three Process Templates, Visual Studio Scrum, Agile Software
00:46Development 6.0 and MSF for CMMI.
00:50We are going to pick Visual Studio Scrum because we are not going to be using all of the features
00:54of Team Foundation Server, which has to do with how do you use the work items and how
00:59to you use the reporting facilities, and so that's what these templates define, they define
01:04work items, they define specific fields, inside the work items for use with Scrum or Agile or CMMI.
01:10In our case, we are simply going to pick Scrum.
01:13If you want additional process templates, you can click on this link and Microsoft has a
01:18whole library of certified Process Templates. So we are going to pick Scrum, click Next.
01:23Now we are not going to branch from any other existing source control so we are just going
01:28to click here, and there is our settings that we want to confirm. Yes, we want to call it
01:34TFS1, that's our description, we are going to use the Scrum template, and we are going
01:39to create a new empty folder with TFS1 at the root, click Finish. All right.
01:44We have successfully created our team project, TFS1 on our default collection of the TFS repository.
01:51So we are going to close this, and we are getting ready to create our first actual set of folders.
01:57In this chapter, we are going to use C# instead of C for our sample code. It is easily
02:02adapted from our examples we have done before, and Visual Studio's TFS integration is very
02:06easy to see and use using C#.
02:09So we will come over here to the Start page, we will click New Project, and we are going
02:14to pick Console Application, and we are going to put this in a directory we are going to
02:18call c:\FSVC1, and we'll call the Solution name.
02:25We are not going to automatically add it to source code control because I want to show
02:28you how to add some of the source code control if you already have an existing solution.
02:33So we will just click OK here and up pops our main Program.cs.
02:39We are going to close that because we are going to use different files and here we now
02:43we can see in the Team Explorer that we can look at the Source Code Control Explorer,
02:47so we are going to do that, and now you can see here, here is our root repository, here's our team project.
02:55All we have is the BuildProcessTemplates under that, we don't have any folders, but we are
02:58about to create that.
03:00You can also now see that here is the local path for where this stuff is stored for the
03:04repository, not for the folder. So let's go back to the Solution Explorer.
03:08Here is our typical Solution Explorer for C# project. We are going to get rid of
03:13Properties here in visual studio.
03:15What you don't see is this column right here, the blank column, is where Source code control
03:21information such as, "Is it checked in?", "Is it modified?", and so forth is going to appear.
03:25So the way we get stared with that is we right-click on the Solution node and select this,
03:30Add Solution to Source Control, the Add Solution to Source Control dialog pops up and asks
03:36us where we want to store our solution inside the TFS server.
03:40In this case, we want to put it inside our TFS1 team project, and we are going to have
03:45a solution folder. We are going to not name it Console Application 1, we are going to
03:49call it TFSSample, and we are going to click OK. And now we can see a few things.
03:55Inside our TFS team project, we now have a folder called TFSSample.
04:00Now this is conceptually the same as a Git repository, a Mercurial repository or an SVN
04:07repository, that particular folder.
04:09As we do additional operations, we will all be operating inside that folder.
04:13You can see this green plus here indicates that this particular folder has been created
04:18and associated with this repository but not yet checked in.
04:22So we open it up here, we can see inside this folder is our ConsoleApplication, inside that
04:27is the Properties folder.
04:30The Folders column only shows folders, not the actual files.
04:34Over here if we look inside the Files, you can see here are all the files that are associated
04:40with that particular thing.
04:41And note now that this TFSSample folder is exactly where we told it to be, inside the
04:47FSVC1 folder and the ConsoleApplication folder was created by the new Project Template to
04:54hold the rest of our files.
04:55We have got everything set up, now let's check in our changes.
04:58To do that, initially here we come to the Team Explorer.
05:01You can see here are our Pending Changes.
05:03We are going to enter in the Comment and click the Check In button.
05:09Visual studio will give you this Check-in Confirmation dialog every time you check in if you want.
05:14In our case, I am going to click the Don't prompt again because I am going to assume
05:17that I know when I am checking in what it is I want to change, or I can also look at
05:21this Pending Changes dialog at any time. All right.
05:25Now you can see Changeset 10 successfully checked in.
05:28Your numbers may vary. It might be Changeset 1 when you first do that.
05:33We did a little bit of a setup on the system to verify TFS is working before we started
05:37to record this chapter, but that's the Changeset number, and TFS uses the word Changeset to
05:42identify things and uses numbers.
05:45So now you can see all of our green plus signs are gone.
05:48Come back to the Solution Explorer, there is now a blue lock indicating that the files are checked in.
05:54So the Solution Explorer acts very similar to shell integration that you might see in
05:59other Source code control systems. So that's it.
06:03We have got our team project created, we've got our Visual Studio project created, we
06:07have got our folders created, we've got our initial stuff checked in, let's get on to
06:11making some changes and checking in and checking out and looking at history.
06:16
Collapse this transcript
Working with check-in, checkout, and revert
00:00Okay, we've got a repository, we've got a project, we've got a Visual Studio project,
00:05let's add some files and check it in.
00:07So in this case, we're going to right-click on the project here and come down to the
00:10Add menu and select Add > Class, and we're going to call this class f1.cs, and here's our class.
00:18So inside our class, we're going to add a function.
00:20The content is from the new project's Haiku error message page.
00:24We're going to pick one that's happened to all of us before we started using Version Control.
00:27So let's come down here and add void func1 (), and we will use Console.WriteLine, which is
00:37the C# equivalent of printf, With searching comes loss, and the presence of absence, My novel\" not found.
00:56Now let's look at the Solution Explorer and see what Visual Studio is telling us.
01:01We can see for ConsoleApplication1, there's a red check mark next to it. That means that
01:06file has been updated and still needs to be checked in.
01:10You can see that f1.cs has a green plus sign next to it. That means that's a file to be
01:17added to Version Control, but not yet checked in.
01:19And as we saw before, for example, Program.cs has a little blue lock icon next to it, which
01:26means it's checked in, it's read-only in your working set until you start making some changes
01:31to it, which also means that your working set for that file is up to date with your repository.
01:36So in order to check this in, we're going to come over here and right-click on the project
01:41line, ConsoleApplication1, and then we're going to select Check In from the menu.
01:46Visual Studio of course always requires you to save everything before you check it in, so we'll say Yes.
01:51Now it brings us back to the Pending Changes tab.
01:54So we can see a number of things here.
01:56We can see we're in our Team Project TFS1, and you can see exactly all the details when I hover over that.
02:03You can see that there are two changes here, and you can see this tree, this shows which
02:09files are being changed.
02:10You can see that ConsoleApplication1.csproj is being updated, and f1.cs is being added.
02:18So in our Comments, we're going to say Add Func1, and then we're going to click the Check
02:24In button, and now we see Changeset 11 successfully checked in.
02:28Let's go back to our Source Code Control Explorer and look a little bit at the status of what's going on here.
02:33We can come to this folder now and right-click and say View History.
02:38Now we can see for, as we did with Git in our initial run-through, this is essentially
02:42the same as a Git log, so here at Changeset 10, we did an Initial Commit, Changeset 11,
02:49we added function 1.
02:50You can right-click here and ask for Changeset Details, and over here you'll see we added
02:56f1.cs and updated csproj.
03:00If we click on this one and say Changeset Details, the Team Explorer now shows us the
03:06fact that we added all these files. So let's close the History pane.
03:10Let's go back to our f1.cs, and let's go back to our Solution Explorer.
03:15So let's make a change so that we can see versioning in action.
03:18So we're going to open this file again, and we're going to make a change, we're going
03:21to change the string My Novel to Website. Now we're going to save the file.
03:29This button here saves the individual file, this button here saves everything, so I tend
03:33to get into a habit of clicking this Save All before I do Source Code Control operations
03:38in order to save me all those dialogues of, oops, you forgot to save that.
03:42So once again, we'll come over here, right-click, and say Check In.
03:46Once again, the Pending Changes dialog pops up, and we're going to say Changed My Novel
03:52to Website and click Check In.
03:55But before we click Check In, I want to make a note of something that TFS does uniquely
04:00from some of the other Source Code Control systems.
04:03Because TFS locks the files, when you check them out to edit, sometimes somebody needs
04:08to go in and make a change to a file before you're ready to check in, and when you need
04:12to do that, what you do is you use this Shelve feature.
04:16So the Shelve feature allows you to preserve your Pending Changes and add this to what's
04:22called a Shelf Set, which is essentially a temporary Check In, so all your work is
04:26saved in the central server, but the mainline is not physically changed so that someone
04:31else can check that out and make their changes.
04:34So in this case, we're not going to do a Shelve, we're going to click Cancel.
04:38We're going to come back and actually do the check in, but that feature can be incredibly
04:42handy when you have a system like this, which has a centralized server, and file locking. All right.
04:48Now we've got Changeset 12 checked in.
04:50Once again, we'll come back to the Source Code Control Explorer and ask for History,
04:55and there you can see, here is our initial Changeset, Add Func1, Changed My Novel to Website.
05:02If we select two Changesets, for example, 12 and 11, we can now right-click and say Compare.
05:09This dialog pops up because you get all kinds of options when doing compares, we won't get
05:14into all the details of that, but this also can work when you've got lots and lots of
05:18files, you can filter by specific file types and so forth.
05:22In this case, we're just going to click OK and look at the differences, and you can see,
05:26ah, these two things are different.
05:28And if we compare the files now, it will actually give us a visual comparison, and we can see
05:34that My Novel got changed to Website.
05:37Note that a Changeset, of course, can contain potentially hundreds of files or thousands
05:40of files, if you've been working on it for days and weeks.
05:44So the Changeset first gives you the level of folder differences, because you might have
05:50additional folders being added and deleted, and then once you've come to that level, as.
05:54As we saw back here, you can actually then compare individual files.
05:59So we'll close this and we'll close this and continue on.
06:04Now, let's make another change.
06:06We'll close the History, come back to our file, and we're going to change Website to Webpage.
06:13Now, we're not going to check it in, but we are going to try to ask for the differences.
06:17So we're going to come back to the Solution Explorer, and we're going to right-click here,
06:22and we're going to compare, and we're going to compare our Workspace Version with the
06:27Latest Version, so we click OK.
06:30And again, we get the visual differencing window here, and you can see that it says
06:36that the server version has Website and our currently updated version that's not yet checked in has Webpage.
06:42So in this case, in order to revert this, all we have to do is close this and come back
06:46to Visual Studio and say Undo.
06:49Now, let's go ahead and update that again to Webpage and save it.
06:56So if we look over in the Solution Explorer, we can see that f1.cs now has a red check mark next to it.
07:01But what if we decided after we've saved it in our local working set, but before we've
07:06checked it into TFS, that this isn't really what we want to do?
07:09Well, you can come over here, right-click on the file, come down to the Source Code
07:13Control menu, and say Undo Pending Changes.
07:17You will get this dialog that says this is going to undo all pending source changes for
07:21that particular file or files that you've selected.
07:23I'm going to click Undo Changes, and it says Undo check-out and discard changes?
07:28I'm going to say Yes to All, and now you can see that Webpage has now been reverted to Website.
07:34Remember, none of your changes in the repository have been lost. You're just updating the working set.
07:39If we go to this file, come down here, and Source Code Control, and say View History,
07:46we can actually completely revert back to this one if we want to.
07:49We can say Get This Version or Rollback Entire Changeset.
07:54So Get This Version will allow us, for example, to say, all right, now I want to have that
07:58version which still had My Novel in it.
08:00Remember, you haven't lost anything. We can come back up here and say Get This Version,
08:06and now we're back to Website.
08:08So that's the basic workflow when working with files in TFS. You simply edit the files,
08:13Visual Studio automatically checks things out, you Check In using the Pending Changes
08:18window, and you use the History window to be able to do differencing and to be able
08:22to revert to other Changesets.
08:25Now let's move on and take a look at labeling in TFS, and then after that, we'll look at branching and merging.
08:32
Collapse this transcript
Tracking history and tagging
00:00Tagging in TFS is called creating labels, and it's really easy.
00:04You do it from the Source Code Control Explorer.
00:06Remember, tagging is the process of identifying a particular set of changes in your repository
00:13with a label so that you can come back later and check that out, such as when you shipped
00:17Version 1, and you start working on Version 2, if you need to roll back to the Version 1
00:22changes so that you can make a bug fix and then come back.
00:26So we'll go to this TFSSample-- that's the name of our project folder--
00:30we'll go down to Advanced and say Apply Label.
00:34And so for our Label, we're going to say v1 and for our Comment we're going to say This is version 1.
00:40Now, you can apply this label to anywhere you want.
00:43You can say the Latest Version, the version that's in your Workspace, a particular Changeset
00:48or a Date or even to another Label.
00:50In this case, we're going to just pick Latest Version and click Create.
00:53And now we see that everything is all set, it is Label v1 that's been created, and here
01:00you see a log of all the other things that we did before, replacing the file with different
01:05versions and creating the label.
01:07So once again, now if we come here and say View History, you can see that not only is
01:12there is a Changesets tab, there is a Labels tab, and this allows you to keep track of
01:17the labels separately from the Changesets.
01:19So now I can do something like come here and say Get This Version.
01:24Now, in this case, it says all files are up to date, we didn't actually do anything.
01:29But if we had gone back to f1.cs and started to make another change and say we said Node
01:36not found and we saved it and we checked it in,
01:46now if we come back to our History and go to the Labels, we can right-click here and
01:49say Get This Version. We come back to look at f1.cs, it's got Website.
01:55But if we come back to the Changesets and Refresh this, and come back and say Get This
02:02Version, we can now see that it's back to Node.
02:05And that's basically all it is to use labels in TFS, it's all integrated into Visual Studio,
02:11and it's all done by using this Labels tab inside the History window.
02:16
Collapse this transcript
Branching and merging
00:00The last major piece of functionality we need to explore in TFS is branching and merging.
00:05Now, branching and merging are done quite a bit differently in TFS than they are, say
00:10in Git or Mercurial.
00:12It actually creates new folders inside your project folder.
00:15So we'll come over here to our Sample and say right-click, create a Branch, and we'll call it branch1.
00:23Now, you can see that there are actually two separate physical sets of folders inside this and this.
00:32You see it's created over here in the Folders section a new branch, and there's a little
00:37T symbol there that indicates that's a new branch.
00:40Like some of the other systems, the branch has been created, but it's not physically
00:43in the repository yet until we check it in.
00:46So we'll come over here to the Team Explorer, and we'll add a Comment, Create Branch1, and we'll check it in.
00:58So now we have our branch created, and you can see that the branch is actually stored
01:03in a completely separate folder, the branch is stored in our project folder under the
01:07folder TFSSample-branch1, whereas our original project is stored over here under FSVC1\ConsoleApplication1.
01:17So in order to switch to the branch, we actually need to open up the appropriate Visual Studio
01:21solution for the files.
01:23So, for example, we'll come back to ConsoleApplication1, underneath branch1, and double-click on ConsoleApplication1.csproj.
01:32So now it looks like we're in the same place, except if we hover on top of the file name, you'll
01:37see that the full file name here says TFS1\ TFSSample-branch1\ ConsoleApplication1\f1.cs.
01:45So if we make a change here, instead of Node not found, we say Dwarf not found, and we
01:51save it, and we can check that in, Change node to Dwarf.
02:00If we now come back to our Source Code Explorer and ask to View History, you see that we have
02:08a completely separate set of Changesets for the branch.
02:11Now, this is different again than the version Git and Mercurial in that there is a set of
02:17Changesets for each branch that are completely independent.
02:21So now if we want to switch back to our other branch, to the main branch, we can come here
02:25to ConsoleApplication1 and once again open up ConsoleApplication1.csproj, and you can
02:31see, not only we are back to Node, but if we hover here, you can see we're back in the FSVC1 directory.
02:37So now let's do something in the branch so that we can actually have something to merge.
02:41We'll go back to our Source Code Control Explorer, go back to our ConsoleApplication1 in the
02:45branch, open up the project again.
02:48Now, we're not only going to change node to Dwarf, we're going to add another function,
02:56and then we're going to check this in, save it, check it in, and once again if we look
03:06at the History of our branch, you can see we have our Add func2.
03:13Now let's go back to the Source Code Control Explorer, let's go back to this original main
03:18branch, open up that project.
03:20Then we are going to come back to the Source Code Control Explorer, and we're going to merge.
03:24So we right-click on the name of the folder, come to Branching and Merging and select Merge.
03:31Now it's going to ask us what we want to merge with, and it's really clear here that it allows
03:37you to decide which way you want to go.
03:38Now, in on our case, this merging is wrong direction.
03:42This says right here the way it's configured now, that would be merging our main branch into branch1.
03:48We want to go the other direction.
03:49So we'll use Browse and select branch1 as the Source, and you can see it automatically
03:56updated the target branch, because TFS is smart enough to know you only have two branches.
04:00If that weren't the case, we can come here and Browse and select the main branch.
04:05Now we'll click Next, and it asks us which type of merging do we want to do?
04:10Do we want to do it to the Latest Version or to a particular Changeset or Label or Date?
04:14In this case, we'll use the Latest Version.
04:17It says all necessary information has been collected, and it's getting ready to merge.
04:20We click Finish button, and the merge is done.
04:24Now it tells us that our file has been modified outside the Editor, because the Editor had
04:30the version that was in the main branch, and when we did the update, it actually updated
04:35the file in our Working Set directory on disk, but hasn't actually updated the Editor, so
04:40we're going to say Yes, we want it to reload.
04:42And now when we come back to f1.cs, you can see, not only do we have Dwarf, because that
04:47was the change we made in the branch, we also have our function 2, so we've successfully
04:52merged back from our branch back to the main.
04:55And if you recall our conceptual overview, this is called a reverse integration, we actually
05:00took what was in the branch and brought it back into the main.
05:04Now, if you're going to continue keep working in the branch over a long period of time,
05:08you'll want to make sure that you do a forward integration by doing that merge in the opposite
05:12direction from the main branch back to your private branch on a fairly regular basis,
05:18for example, weekly, to make sure that your private branch doesn't get too far out of
05:22date with changes that other people are making to the main branch.
05:26That's actually it for TFS.
05:28Since we've used TFS only with the GUI, there isn't any movie for using GUI and shell integration,
05:35because TFS integration is all done completely inside Visual Studio.
05:38I hope you've liked the overview of TFS.
05:42Obviously, Microsoft has tons of additional documentation videos on Channel 9, lots of
05:48information on being able to understand how to more effectively use Team Foundation Server.
05:55
Collapse this transcript
7. Git
Installation and setup
00:00Okay, let's roll up our sleeves and do a little Source Code Control with Git.
00:03Git is a distributed Source Code Control system.
00:07That means that you host the entire repository on your development box and other people host
00:12the same complete repository on their development boxes, and you can exchange files back and forth.
00:19It also means that you can use things like GitHub, which is a cloud-based service to
00:24host repositories in the cloud in order to save your work off of your development system,
00:29if you're working by yourself. Git is free. You can get the bits from git-scm.com.
00:35And you can use GitHub if your product is open-source to have free-hosting.
00:40If your project is not open-source, you can have private repositories on GitHub for a
00:45very reasonable price. That's what I use on a regular basis, also at github.com.
00:50And they also have their own custom GUI application for both Windows and Mac that allow you to
00:57easily manage your local repositories and syncing to your repositories on GitHub and
01:03keeping the two of them connected together. All right.
01:06So let's dive in and install Git.
01:09Okay, let's roll up our sleeves and do some Source Code Control using Git.
01:15The link for the Installation Binary is in the Links.rtf file in the exercise files directory.
01:21We're using the Git Installer from the git-scm.com website, which is the main home of Git, and
01:27it's a very forward MSI.
01:29This is the very latest one as of the time that we're recording this course.
01:33And we can put it wherever we want.
01:36And we're going to choose Run Git from the Windows Command Prompt, because it works best
01:42with our recording setup here.
01:44If you're a Mac person or a UNIX person working on Windows, you probably want to Use Git Bash
01:50only, and then you have a very familiar command shell.
01:52In this case, we're just going to click Next.
01:55And in our case, because again we're using Windows, we're going to use Checkout Windows-style
01:59and commit Unix-style line endings.
02:02That allows us to use this repository easily with Macintosh users and Linux users.
02:07If you're going to use Windows only, then you can click this Checkout as-is commit as-is.
02:12All this affects is what is stored in the repository, not what is in your working set.
02:18So when in your working set you always have carriage return line feeds, it just strips
02:22out the carriage returns when it checks in and reinserts them when it checks out for textual files.
02:29Unzip a bunch of Git stuff, we're all set, we don't need to look at the ReleaseNotes,
02:34and the way we can find out if we've actually got Git installed, first of all, you can see
02:38the icon here for the Git Bash shell, if we wanted to use it.
02:42And we'll open up our Command window and say git --version, and you'll see something like this.
02:47Now, your version maybe different, but if you get a message at all like that as opposed
02:52to command not found, you know you've got Git successfully installed. All right.
02:56Let's move on to creating your repository and doing some checking in and checking out.
03:01
Collapse this transcript
Creating a repository and a project
00:00All right, let's create a Git repository.
00:03Git repositories, unlike TFS and Subversion, actually live in the directory with your files.
00:08There is no separate repository directory.
00:11All right, so let's create a directory to store our Source Code files.
00:14We'll create mkdir g1, then we'll put CD into there, and we'll say git init.
00:21That initializes that empty repository.
00:25We can validate it by saying git status, and it says nothing to commit, and that's all
00:30there is to creating a Git repository.
00:32If we do git dir/a, you can see that there is a hidden directory here called .git, where
00:38all of the metadata is stored.
00:40What's important is that if you want to backup a Git repository with all the history, you
00:44backup the entire directory here with all your Source Code files, including this .git folder.
00:49So depending on the compression tool you're using, make sure that after you've made the
00:54ZipBackup or the 7zbackup that, that folder is actually in your archive.
00:59And that's it, that's all there is to creating a Git repository.
01:02Let's move on to creating some files and doing some check-ins and check-outs.
01:07
Collapse this transcript
Working with check-in, checkout, and revert
00:00Okay, we've got a Git repository inside of our directory g1 here.
00:05Before we start adding things, let's set two git configuration items which will help us
00:10make sure that all of our changes are marked with our name and our email.
00:15So we say git config user.name and git config user.email.
00:29No, that's not my actual email. And now we can put in some code.
00:33The content we're going to use is from the new project's haiku error message page.
00:38We're going to pick one that's happened to all of us before we started using Version Control.
00:42I'm going to create f1.c and main print f. With searching comes loss, and the presence of absence.
01:02"\My Novel\" not found.\n".
01:14Now of course, this isn't going to ever happen to you again now that you started to use Version
01:17Control, but you know how that feels. So we'll save the file, and we'll exit.
01:22Now we'll add that to the repository in two steps.
01:25First, we have to tell Git to start tracking that file by saying git add f1.c, and we
01:30ask Git the status of our working set. It says there is a new file ready to be checked in.
01:36So now we'll add it to the repository, git commit, and you can see it created one file.
01:47If we ask Git for the status, it says there is nothing new to commit.
01:51And if we ask Git for the log, you can see we have a message here that says there is
01:56our Initial check in commit message and three additional lines of information which we're
02:01going to look at here.
02:02The first line is the commit ID, or essentially changeset identifier.
02:08That's a 40-digit-long hexadecimal number, which is a GUID, or a Global Unique Identifier.
02:15Now, for most usage inside Git, you'll only need to type the first four or five characters
02:19of that GUID, so don't get scared by the fact that it's going to be starting to ask you
02:23to type in 40 digit numbers.
02:26But you have to type in at least as much of that in order to be able to uniquely identify
02:30a changeset as necessary.
02:32So especially on your own system, it's probably four digits.
02:34When you start working with more people, it's probably five or six at the most.
02:38So now let's make a change so we can see Git's versioning in action.
02:41We'll once again open up f1.c, and we're going to change My Novel to Website, maybe a more
02:53appropriate message for the internet age.
02:55And now we're going to check it in again, but this time we're going to use an editor
02:59feature that's built into Git in order to do our commit message.
03:03So we're going to say git commit -a, and Git opens up in this case, Vim, a editor that
03:11allows you to put in your commit message.
03:12So we're going to say Changed my novel to website, and since this is Vim, it understands
03:19all those wonderful VI commands that you might know and love. In this case, what I do is I
03:24hit the Escape key and then I type :wq to Save it and Quit, and now it does the commit.
03:31And if we do git log, you can see now we have two changes, both our Initial check in and
03:38Changed my novel to website.
03:40If you just want to see the changeset IDs and the comments, you can say git log --one line --all,
03:49and now we have--you can see the first seven digits of each one of those changeset
03:54IDs and the commit message.
03:57So now let's make another change and then look at it and decide if we want to roll it back.
04:00So once again, we're going to open up f1.c, and we're going to change Website to Webpage,
04:07and we're going to Save the file.
04:09Now, if we want to see the difference between our working set and what's in the repository,
04:14we can say git diff, and you can see it shows the one line has changed from website to web page.
04:21Now, this show the difference with all files that are currently changed in the working set.
04:26If you want to see changes just for a single file, you can say git diff and just put in the file name.
04:31Now, in our case it's going to be exactly the same, but if you had 25 files, that might
04:35generate quite a bit of output.
04:38You can also ask for the differences between the working set and a specific changeset.
04:42So if we do git log, we can see we've got our two change sets. Let's ask for the difference
04:48between our working set and not the most recent one where we changed My Novel to Website,
04:53but the initial one where initially we checked it in and where we had My Novel.
04:56So we'll say git diff, and we're going to put in 87b53, and we'll see what happens.
05:06So now you can see the difference between that commit which we called our Initial check in
05:10and the current state of our working set.
05:12You can see our current working set in green here says Webpage and the Initial check in said My Novel.
05:18Now, your changeset IDs are going to be different than these.
05:21You'll need to run git log on your system and type in the first five digits of the actual
05:26IDs on your system, because GUIDs are partially generated by the Mac address for your Ethernet
05:33adapter in your computer and so it will be clearly different than the system on which we're recording this.
05:38So now let's roll back to our most recent commit.
05:41So we'll say git checkout HEAD f1.c.
05:47If we type f1.c, you can see we're back to Website.
05:52You can also revert to any particular revision, not just the topmost one, by using the checkout command.
05:57So we'll say git log, and now we're going to revert back to the initial one, so we're
06:04going say git checkout 87b53 f1.c, and now if we type f1.c, you can see we're back to My Novel.
06:16Note, none of the changes in your repository have been lost. You're just updating the working
06:20set to the one that you want.
06:21So for example, we can go back to git checkout HEAD f1.c, and we're back to Website.
06:30All right, that's the basic working flow of checking in, checking out, and reverting with Git.
06:37Let's move on to tagging and labeling with Git.
06:42
Collapse this transcript
Tagging
00:00Tagging in Git is really easy. Tags are called tags.
00:04To create a tag, we'll say git tag, add the tag, v1, and then we'll add a message to indicate
00:10what it is we want, like Label version 1.
00:16Now to see the tags in your repository, it's as simple as saying git tag.
00:20To see what's in a specific tag, you can just type git show and the tag, and here we can
00:25see that the tag is shown, and it specifically shows up here at the top that I made the tag
00:30and when I did and exactly what is in there and what the various differences are between
00:35that tag and what's in my working set.
00:37Now, if I want to go back to that tag at a later date, for example, in order to fix the
00:41bug, I can say, git checkout v1, and if I want to get back to the HEAD, I can say git checkout HEAD.
00:52Because branching is very easy in Git, you want to do a checkout to your tag and then
00:56do a branch there to allow you to make sure your changes are independent of whatever changes
01:02you were actually doing at the HEAD.
01:04So for example, if you had to come back to version 1 three months from now, you'll do
01:08a checkout v1, you'll branch at that point, make your changes there, and you may merge
01:13them back into the main branch, or you may keep that separate as your version 1 branch from now on.
01:19One last thing. If you want your tags to be copied to a remote repository, you have to
01:23use the command git push --tags, like this, and if you want to pull them from a remote
01:31repository you use git pull --tags, with the appropriate additional arguments here that
01:36indicate which repository you're pulling from or pushing from.
01:40So tags are not by default automatically copied on a push or pull.
01:45All right, that's tags in Git. It's really, really simple. It allows you to just back up
01:50to wherever you were at that particular point and carry on.
01:53Again, I highly recommend if you're going to use tags, when you do a git checkout at
01:58a particular tag, do a branch at that point. As you'll see in the next movie, branching
02:02is really easy so that you make sure that you carry on with your version 1 independently
02:07of the changes you might have already made up to that point, say when you're working
02:10on version 1.1 or version 2.
02:15
Collapse this transcript
Branching and merging
00:00The last major piece of functionality we need to explore is branching and merging.
00:05In Git, branching and merging is very easy and very lightweight.
00:09So first, let's run Git branch. We can see we are on the master branch.
00:14This is sometimes called the trunk.
00:17To create a branch is as easy as saying git branch b1, and now we have a new branch, you
00:24can see we have branches b1 and master.
00:27And you can see between the asterisk and the text in green, they we're on the master branch.
00:32So in order to make changes in the branch and work with that, we need to check that branch
00:36out and then we can make updates.
00:38So git checkout b1, I can see it says we switch to branch b1. If we do git branch, you
00:46can see we are on branch b1, so now we'll go and update our file and add a new feature. One more haiku.
00:54"No available space," "Look to the cloud," "Your drive is full".
01:05I will save that, we will exit, and then we'll commit that in the branch.
01:13Now if we say git log, you can see that we have the Update in branch, and you can see
01:20we have changed my novel to website, and we can see we have Initial check in.
01:24But there is nothing there that makes it clear that the update was done in the branch because
01:28the set of revisions is global between all the various different branches.
01:33So let's make another change, and we'll go specifically and make the commit message to
01:36show what is what we want to do.
01:38So we'll say Notepad f1.c, and we'll come down here and change the word Website to Node,
01:47and save that, and we'll quit and then we'll do another commit, and we'll say b1 Change website to node.
02:00And there's a convention that's just handy to know which branch you are making the changes in.
02:04So now if we say git log, you can see it's very clear that that change was made in branch number one.
02:10All right. Now let's talk about merging.
02:14If you continue to work in a branch for an extended period of time, you'll want to do
02:18a merge from your main branch back into your private branch. Remember, that's called a forward integration.
02:24Time to do this varies depending upon how active the main branch is.
02:28So usually I do that weekly if I am working in a project with somebody so that I make
02:33sure that my private branch is up to date in all the places where I am not currently working.
02:38Now in our case, we are simply going to do a reverse integration from our branch b1 back into the master.
02:45So the way you do this is you first switch back to the master, and if we type f1.c,
02:51you can see we don't have our new feature, and it still says website.
02:55Now we are going to merge, git merge b1, and now if we type out f1.c, you can see it not
03:02only has the word Node, it also has our second function, feature1.
03:06You'll see one thing up at the top there where we did the git merge b1, it says Fast-forward,
03:12and that means that Git recognizes that b1 came off of a common starting point with our
03:19master branch, so therefore, it was able to replay the changes very, very quickly by knowing
03:24that it didn't have to like start looking at everything because it knew where they both began to differ.
03:30Well, that's it for branching and merging in Git.
03:33Next up, we'll take a look at some shell integration and some GUI tools for Git that were installed
03:38when we installed the Git installation that we got from git-scm.com.
03:43
Collapse this transcript
Working with GUI clients and IDE integration
00:00The latest version of Git that you can get from git-scm.com has built-in GUI tools and
00:08shell integration. As you can see here, we've got something we can create, Git and add all new files.
00:14There is a specific Git Commit tool, a Git History tool, we can fire the whole thing
00:19up by calling up for the Git GUI, and it knows which repository you can see up here in the
00:25title bar, it's using because we right-clicked on that particular folder.
00:30So you can see there aren't any Unstage Changes or Stage Changes in here.
00:34We come up to Repository and say Visualize master's History, and there's our changes.
00:40That's our Initial check in. You can see down here at the bottom, there is our initial text. We go up one.
00:46Now you can see it shows the dif where we took out my novel and put in website.
00:50Here's what we added, the feature code to our branch, and up here is where we added node.
00:58And you can see by the fact that it now has this b1 and master at the same spot on the top line there,
01:03those two branches have been merged together.
01:06In addition to doing that, you can browse master's Files, or you can browse files in
01:11various different branches if you've been asked for Database Statistics.
01:14For example, here we can see these are statistics that have to do with the way in which Git
01:20manages things, and it basically never deletes anything.
01:23So over time, you start using this, for 6 months or a year,
01:28you may end up with a lot of extra files that are no longer being tracked by Git that are
01:32still in that hidden.git directory.
01:35You can use this tool to commit it and compress that and get rid of the unnecessary files
01:39that you are still carrying around if you're backing up the entire directory.
01:42And that's it for Git GUI and Git shell integration.
01:45I think you'll find that Git is very, very easy to use, very lightweight, and something
01:50that I highly recommend. It's also being used very, very widely in the open-source community,
01:56especially with a website called github, g-i-t-h-u-b.com, which has free hosting for open-source projects,
02:04and I also highly recommend github for hosting private repositories for a very reasonable
02:09price that allows you to then push the changes from your local repository to the cloud.
02:14And if you remember my story from the beginning of the course, I was talking about restoring
02:17my hard disk, it was on github where my files were located in the cloud, and it was very easy.
02:23All I did was went to github and did a pull down form the github cloud version, and my
02:27local repository was completely restored.
02:30And finally, as we did with Subversion, we're going to zip the entire finished copy of the
02:35Git repository here we have in directory g1 and put it in the exercise files for this chapter.
02:40
Collapse this transcript
8. Mercurial
Installation and setup
00:00Let's do some source code control with Mercurial.
00:03Mercurial is a distributed control system similar to Git, which means that the repository is hosted on your box.
00:11You can also host repositories on another developer's box and they host the same complete repository,
00:17and you exchange information either with pull and push or with import and export.
00:22And then you can also have server-based connections to Mercurial repositories which allow you
00:27to use pull and push to repositories in the cloud for shared repository use.
00:32It's free, and there are also commercial hosting options.
00:35You can get the free version, as it says, here on the screen, at mercurial.selenic.com/wiki/Mercurial,
00:42and there's also commercial hosting from a company called atlassian.
00:46We're going to install a local version of Mercurial which is abbreviated Hg, as in the
00:50elemental symbol for Mercury.
00:52Because Mercurial is such a tongue twister, I'm going to call it Hg throughout the remainder
00:57of movies in this chapter.
00:59The link for the installation binary is in the Links.rtf file in the Exercise Files directory.
01:06Let's go ahead and fire up the setup here, and we'll go through the setup wizard, we
01:10do accept the license terms, then we're going to install the complete package and accept
01:14the location for the default directory. Now we're going to click install.
01:18All right, and that's it. Now we've got Mercurial installed.
01:22Now let's fire up a command line and make sure our installation is correct.
01:27Just like with Git, we can just do hg-version, and so we go we've got been Mercurial Distributed
01:33SCM (version 2.3.2), your version maybe newer depending on how long after we've got finished
01:40recording this course that you downloaded your installation Mercurial.
01:43We're all set. We've got it installed. Let's go make a repository and some projects.
01:48
Collapse this transcript
Creating a repository and a project
00:00Hg repositories live in the same directory with the files.
00:05Unlike Subversion, Perforce, and TFS, there is no separate repository directory.
00:10Like Git, this makes it possible for you to backup the entire directory, say, with zip
00:15and not only back up your files, but also back up all the version control metadata in a single place.
00:21So first, let's create the directory. I'll call it hg1, then we'll CD to hg1, and we'll do hg init.
00:30Like Git, Hg stores all of its metadata in a hidden directory here called .hg.
00:37If we run hg status, unlike Git, we don't see any message because there's nothing going in our repository.
00:44If you haven't properly initialized the repository and you ran hg status, you we'll get an error
00:49message telling you that no repository was found.
00:52Since we got just a blank response, we know we're all good to go.
00:56Let's move on to creating some files and checking in and checking out.
01:01
Collapse this transcript
Working with check-in, checkout, revert, and tracking history
00:01All right, we've got a working HG repository. It's time to add some files and check it in.
00:07Mercurial is different than some of the other systems because we have to do one piece of
00:10initialization globally before we can start checking things in.
00:13What we have to do is to create a file in the user profile called Mercurial.ini, and
00:20inside of it we had to put in our username and email address.
00:23So we'll say Notepad, %userprofile%\Mercurial.ini. It doesn't exist, we do want to create it.
00:33I copied the text that we need onto the clipboard, so you will type in ui, then username = and
00:38here you will put in your username, and over here you'll put your email address.
00:46Just remember, this is not a real email address. Don't try sending email there.
00:51Okay, now we have got Mercurial fully initialized.
00:54We can start putting in some code. So let's open up Notepad and create our file.
01:00The code we are going to put in has some content from the new project's haiku error messages page.
01:04We'll pick one that's happen to all of us before we start using Version Control "With
01:08searching comes loss\n", "and the presence of absence:/n", and then the kicker "My Novel\" not found.\n".
01:25Well, at least this one will never happen to you again, now that you are going
01:28to be a Version Control expert. All right. We'll save it.
01:33Now if we do hg status, you can see that HG sees it but doesn't know what to do with the file.
01:39So we need to tell it that this is a new file for the repository, hg add f1.c.
01:45Okay, now we can ask Hg the status again and see that it's got the file ready to add.
01:52So finally, remembering that we set up our Mercurial.ini file at the top here, we'll
01:56check it in, and everything would be fine, hg commit -m "Initial Checkin". All right.
02:04Now if we ask Hg status again, you will see there is nothing going on, and then we see hg log,
02:10and you can see that it puts out five lines for each changeset.
02:14If you look at the first line, you can see the changeset identifier.
02:18Now in Mercurial there is two numbers, one-- 0 in this case--is the local identifier that
02:24you can use for doing things like reverting and versions. We'll see that later on in this movie.
02:29The second is a hash that's used to uniquely identify this changeset so that when this
02:36changeset is for example exported or pushed to a remote repository, they can make sure
02:41that they can uniquely identify that from other changeset zeroes that might come in from other users.
02:47You can see our user as we set it up in the Mercurial.ini file, the date, the summary
02:52and so forth where you see tag: tip--that's the same as Git Head--and it essentially says
02:58this changeset was added to the most recent version of repository.
03:02So this is the top or the tip of the iceberg here that has everything in it, that's the very latest stuff.
03:07So, now let's make another change so we can see Hg's versioning in action.
03:14We'll open up our file, and we'll change My Novel to Website and then we'll save it.
03:23This time we are going to do hg commit, but we are not going to put a message audit on
03:28the command line here, we are going to let it open up Notepad so that we can put in a multi-line message.
03:34So we'll say Change My Novel to Website, This is a better change for modern times. We'll save it.
03:48Now if say hg log, you will see that you only see the summary.
03:53If you want to see the full commit messages, you have to say hg log -v.
03:58And there you can see in our changeset, number 1 there. It's--instead of saying summary, it
04:03now says description. All right.
04:05So now let's make another change and then examine how to revert or rollback.
04:09Once again, we'll open up f1.c, and we'll change Website to Webpage, and we'll save it.
04:19If we run hg diff, you can see that if we committed this change. It would change Website
04:26to Webpage, and you can see it shows you the difference between what's in your working
04:31set and what's in the repository.
04:34Note in our case, we only have one file. If you had 25 files, when you said hg diff,
04:39it would show the difference in all of the files.
04:41You can ask it to show you the differences in only a single file by typing hg diff f1.c.
04:46Now in our case, that's exactly the same since we only have one file, but you understand
04:51now how to see the difference for an individual file.
04:54There is a lot of additional options on the diff command so that you can ask it to show
04:57you the difference between different times, and you can also ask it to show you the difference
05:02between the working set and a specific changeset.
05:05If we do hg log, we can see that we have changeset 1 and changeset 0.
05:10So if we say hg diff -r 0, it will show us the difference between our current working
05:17set which has web page and the initial Checkin which had My Novel. All right.
05:23So now let's roll back to our most recent commit, and we do that by saying hg revert
05:28in our file name, we type out f1.c, and you can see now we are back to website.
05:34Finally, you can also revert to any revision, not just the topmost one by using the revert
05:38command and specifying a changeset so that we'll do hg revert -r 0 f1.c, and again we
05:47type out f1.c. You can see we are back to My Novel.
05:50Now, note none of your changes in the repository have been lost, you are just updating the working set.
05:55So if we just say hg revert f1.c, you can see we are back to website.
06:01So that's the basics of checking in and checking out and reverting with Hg.
06:06Now let's move on to talking about tagging.
06:11
Collapse this transcript
Tagging
00:00Creating tags in Hg is really easy. First, let's see what tags are in the repository.
00:05In our case, there's only the one marked tip which represents as I said before the very
00:12most recent changeset in the main branch along the trunk.
00:16Again, remember the numbers, you see on the screen the changeset ID and the hash may
00:21differ between this system and your system.
00:24Create a tag it's very easy, hg tag v1, and now we do hg tags.
00:31Now we can see that we now have two tags tip and v1 to check out the version marked by
00:38a tag we use hg update.
00:41But let's make a tag without tag v1 now. Let's make a change to our mainline and check it
00:46in so that we can switch back and forth between the tag and the mainline we can see the difference.
00:51So we'll come in here, and we'll change this colon to an ellipses, we'll commit that,
01:07and now we type f1.c. You can see we have the ellipses there, but if we see hg update,
01:15now we type f1.c, you can see it's back to a colon, and if we type hg update, and
01:27you can see it's back to the ellipses. So that's how easy it is to do tags in Hg.
01:32Just remember when you switch back to the tag, you're essentially moving the update pointer backwards.
01:37So you may want to create a branch if you're going to be making changes when you switch
01:41back to say version 1 in order to make an update to version 1 of your source code.
01:45But branching and merging is very easy in Hg, and we'll see that in the next movie.
01:50
Collapse this transcript
Branching and merging
00:00Let's explore branching and merging in Hg. In Hg, branching and merging is very easy.
00:06First, let's run hg branch and see that there is only one branch default, and that's the one
00:11we're on. Sometimes it's called the trunk. But in Hg, it's called the default.
00:15So to create a branch, we say hg branch b1.
00:19Now notice it says mark the working directory as branch b1.
00:22It hasn't actually done the branch yet, so we have to commit it to make the branch.
00:29Okay, now if we say hg branch, you can see we're on branch b1, and if we see hg branches,
00:38you can see there are two branches, b1 and default.
00:41Now to work with a branch we simply update to the branch, hg update b1, and we ask hg
00:49branch it tells we're on b1, and if we say hg update default and we type hg branch,
00:56we're back on the default branch. So let's go back to branch b1 and make a change.
01:03So we'll add another feature to our little haiku up here "No more available space,"
01:16"Look to the cloud," "Your hard drive is full!"
01:29Now if we save this and commit it--and remember now we can say hg branch--and see that we're
01:38in branch b1, type out f1.c, and see that we've got the new feature. If we go hg update default,
01:45type out the f1.c, you see we just have the original values.
01:50I'll go back to the branch, I will look at the log, and you can see that it shows us
01:58in the list which branch it was in. So it was in branch b1 that we did the update.
02:03Like Git, however, it's a good convention in your summary to indicate which branch the changes are in.
02:10So now we're going to go make one other update, and we're going to change website to node
02:19and then we'll commit that, and we'll put the branch number in front of it, so we know
02:25exactly where we did, what we did.
02:28All right, so now let's talk a little bit about merging.
02:32If you continue to work in a branch for an extended period of time, you'll want to do
02:36a forward integration from the default back to your private branch.
02:39Remember back in the conceptual section we talked about forward integration and reverse integration?
02:45Forward integration is that process of taking things from the main or the trunk or the default
02:49and moving them into your private branch.
02:52The purpose of doing this is to make sure that your private branch doesn't get too far
02:55out of date with the main, if you have other people working on the main branch
03:00so that you're collecting together updates perhaps in sections of the application that
03:04are different than the one you are working in.
03:07Now in this case, we don't have anything useful in our main branch to bring forward, so we're
03:11just going to do a reverse integration.
03:13Remember, a reverse integration is taking changes from our private branch and putting them back in the main.
03:18In order to merge, we need to switch back to the master branch or the default branch.
03:23So we're going to say hg update default, we can see we just have our original data, and
03:29then we're going to ask it to merge branch b1 get back into the default branch.
03:35And notice it says here, again, branch merge, don't forget to commit.
03:39If we see hg status, you can see that not only does it have modified file f1. It also has
03:45this file it doesn't know what to do with code f1.c.orig, and you should just leave
03:51that alone, and in this case, we're going to do the commit, and if we do hg log, you can
04:01see that now we have our updated from branch b1, and that's it.
04:07Now we type f1.c, you can see we have all our changes from the branch merged back into
04:13the default, we can verify when the default branch by saying hg branch and see that we're
04:18in the default branch.
04:20So that's branching and merging in Hg. Next step, we'll take a quick look at looking at
04:25GUI tools and shell integration for Hg.
04:30
Collapse this transcript
Exploring GUI and shell integration
00:00Okay, in order to get GUI support for Hg, we use a free tool called TortoiseHg.
00:06The link for downloading this you'll find in the Links.rtf file in the Exercise Files directory.
00:14Go through, we accept the license terms, we want to have everything installed the complete
00:18package, we'll leave the default installation directory alone, and the setup here will take
00:24just a second, and now we're all finished.
00:29Now let's go back to our Explorer and look at the files on here, and if we go into Hg
00:37you right-click on Hg, you'll notice that it sees that now that this is an Hg directory.
00:42If we right-click on something else, you don't see HG commit, but if you see HG Commit,
00:48you know that that particular directory has an HG repository in it.
00:52So if we look at HG Workbench, this allows us to see the full GUI that is supported by these tools.
00:59You'll be able to see here a graphic representation in that railroads diagram there on the left
01:04of our branching and merging.
01:07Some of the other things you can do with this shell integration is you can go in here
01:11into the directory, click on the file, and say things like Revision History or Remove or
01:18Forget files, Rename or Revert all from inside your visual shell.
01:22And that's it for Mercurial. We've created a repository, we've added some files ,checked
01:28in, checked out, reverted, we've done some tagging, we've done some branching and merging,
01:34and that will get you up and going on distributed version control with Mercurial.
01:39
Collapse this transcript
Conclusion
Selecting a software version control that is right for you
00:00Well, we've made it this far. We've covered the concepts of what is software version control.
00:06We've talked about the concepts of checking in and checking out, reverting, rolling back,
00:12branching, merging, tagging, labeling, and we've covered it in detail for five different
00:18products: Subversion, Perforce, Microsoft's Team Foundation Server, Git, and Mercurial.
00:25With all this information, how do you make a decision as to which one is right for you?
00:30Well, there's two main considerations.
00:33One, if you're working in a team, and you're working in a company, or you have a client
00:38who already has an existing centralized version control server, you are pretty much going
00:42to use what it is they ask you to use, and that'll probably either be Subversion, Perforce, or TFS.
00:49If you're starting up your own team, I would highly recommend using Git or Mercurial.
00:53Both Git and Mercurial each have different followings and different key features.
00:58That might be a decision for you. For me, I most often use Git for two reasons.
01:04One, there is integration for Git inside Apple's Xcode Development Environment, and there's
01:09also integration for Git available for Visual Studio, and two, Git hub, which I mention during
01:15the chapter on Git, is a hosted service, which is free for open-source projects and very,
01:21very low cost for private repositories for commercial projects.
01:26And it makes it very, very easy for you to use the Git repository on your local device
01:32and then push your changes periodically to the server on the cloud to the Git hub server.
01:36Now if you remember back to my original story about restoring my hard disk, Git hub was the
01:41service that I used when I was restoring my drive, and it worked very well from me.
01:46If you're working in an environment where you're really working with the distributed
01:49team, sometimes Git and Mercurial can be best
01:52because you can export and import and send the differences by email without having to
01:57set up a server infrastructure for all of your team members.
02:00And remember Git is what's being used for the Linux Kernel by a team of a few hundred developers.
02:07After digging into all five of these products, you'll probably have a feel for which one suits
02:13your working style the best.
02:15So if your organization doesn't mandate the use of a particular version control software system,
02:20pick the one that you feel works best for you.
02:23If they all seem equal to you, I'd highly recommend using Git. It's lightweight and
02:27it's efficient and it does the job.
02:30
Collapse this transcript
Next steps
00:00Now that you've seen an overview of Software Version Control,
00:04what are your next steps? Well, if you decided to use Git
00:07I highly recommend watching the Git Essential Training from the lynda.com online training
00:12library here, done by Kevin Skoglund.
00:15If you decided to use Subversion, you can get everything you need to know about Subversion,
00:18including a free book here at subversion.apache.org.
00:24If Perforce is what you want to use, or Perforce is what you are required to use by your enterprise,
00:28all the information you could ever want is here at perforce.com.
00:32Information about Microsoft's Team Foundation Server, including the Team Foundation Server
00:36express Edition 2012 is available here at this address at microsoft.com.
00:43The canonical download for Git is available here at git-scm.com.
00:48And finally, Mercurial's home is here at material.selenic.com.
00:54So that's an exploration of the Fundamentals of Software Version Control.
00:58Hopefully you'll find one that does just exactly what it is you need to do, and you'll never
01:02have to read one of those error message haikus ever again. Happy versioning.
01:08
Collapse this transcript


Suggested courses to watch next:

Foundations of Programming: Fundamentals (4h 47m)
Simon Allardice

Git Essential Training (6h 26m)
Kevin Skoglund


Are you sure you want to delete this bookmark?

cancel

Bookmark this Tutorial

Name

Description

{0} characters left

Tags

Separate tags with a space. Use quotes around multi-word tags. Suggested Tags:
loading
cancel

bookmark this course

{0} characters left Separate tags with a space. Use quotes around multi-word tags. Suggested Tags:
loading

Error:

go to playlists »

Create new playlist

name:
description:
save cancel

You must be a lynda.com member to watch this video.

Every course in the lynda.com library contains free videos that let you assess the quality of our tutorials before you subscribe—just click on the blue links to watch them. Become a member to access all 104,141 instructional videos.

get started learn more

If you are already an active lynda.com member, please log in to access the lynda.com library.

Get access to all lynda.com videos

You are currently signed into your admin account, which doesn't let you view lynda.com videos. For full access to the lynda.com library, log in through iplogin.lynda.com, or sign in through your organization's portal. You may also request a user account by calling 1 1 (888) 335-9632 or emailing us at cs@lynda.com.

Get access to all lynda.com videos

You are currently signed into your admin account, which doesn't let you view lynda.com videos. For full access to the lynda.com library, log in through iplogin.lynda.com, or sign in through your organization's portal. You may also request a user account by calling 1 1 (888) 335-9632 or emailing us at cs@lynda.com.

Access to lynda.com videos

Your organization has a limited access membership to the lynda.com library that allows access to only a specific, limited selection of courses.

You don't have access to this video.

You're logged in as an account administrator, but your membership is not active.

Contact a Training Solutions Advisor at 1 (888) 335-9632.

How to access this video.

If this course is one of your five classes, then your class currently isn't in session.

If you want to watch this video and it is not part of your class, upgrade your membership for unlimited access to the full library of 2,025 courses anytime, anywhere.

learn more upgrade

You can always watch the free content included in every course.

Questions? Call Customer Service at 1 1 (888) 335-9632 or email cs@lynda.com.

You don't have access to this video.

You're logged in as an account administrator, but your membership is no longer active. You can still access reports and account information.

To reactivate your account, contact a Training Solutions Advisor at 1 1 (888) 335-9632.

Need help accessing this video?

You can't access this video from your master administrator account.

Call Customer Service at 1 1 (888) 335-9632 or email cs@lynda.com for help accessing this video.

preview image of new course page

Try our new course pages

Explore our redesigned course pages, and tell us about your experience.

If you want to switch back to the old view, change your site preferences from the my account menu.

Try the new pages No, thanks

site feedback

Thanks for signing up.

We’ll send you a confirmation email shortly.


By signing up, you’ll receive about four emails per month, including

We’ll only use your email address to send you these mailings.

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

By signing up, you’ll receive about four emails per month, including

We’ll only use your email address to send you these mailings.

Here’s our privacy policy with more details about how we handle your information.

   
submit Lightbox submit clicked