Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
Okay, we've got Perforce and all of its tools installed, but unlike some of the other tools we're using in this course, Perforce works directly with the file system as opposed to having the GUI client be integrated and automatically create folders and files from inside that client. So what we need to do now is open the Windows Explorer and switch to our Work directory. And inside here, we're going to create a directory within a workspace called p1.
Now if we switch back to the Perforce client, you don't see it yet, but once we click this, Refresh, there is our folder p1. Perforce manages files, not folders, meaning we have to actually create a file in order to get Perforce to add this folder to our workspace. So we'll come back here, we'll go inside p1, and we'll right-click and say New Text File, and we'll put in ReadMe.txt. Doesn't have to have anything in it. In our case, let's come back to Perforce, refresh again, and now we open up p1, you can see ReadMe.txt.
You can notice that this has blank icon that means that Perforce recognizes that that's not in the depot. The way we add it to the depot is we right-click on it, and we say Mark for Add. Perforce can have a whole bunch of pending changes lists. You can have something you're working on over here and something you're working on over there and the default change list. For everything we're doing in the course, we're going to use the default change list, so I'm just going to click Don't show this dialog again. But you can create multiple change lists if you want to be working on certain things and hold back changes and not check them in until you're ready.
But in our case, we're going to be checking in the changes every time we make a change. All right, now that we've marked that for add, we can see a few things. First of all, down here at the bottom, you can see the fact that this in fact has been marked for add. This is actually the command-line version of that command, and you can see what I meant about the fact that there is all these complicated flags in order to simply just add a file to the repository. You can also see over here in the Details pane where the actual file is, where it's going to go on the repository, which revision it is the date and time, the type of the file and which kind of file Perforce thinks it is.
Perforce's file types have to do, whether they're text or binary, so that knows which kinds of different thing to do when doing differencing and merging. So we've got our file, it's got now a text icon, and it's got a plus, meaning it's marked for add. And so let's go ahead and add that in to the repository, and we'll say Submit. And this is the Changelist Submit dialog we're going to say Create folder p1 with ReadMe. And we'll say Submit, and now you can see we have a nice little green dot there indicating that it's up to date in the repository, and our working set has the latest version.
Now let's add some code and understand the lifecycle working with Perforce. The content we're going to use is from the new project's Haiku Error Messages page. These aren't actual Haikus, but they kind of feel like one. We're going to pick one that's happened to us all before we started using version control. Again, we have to create files by using the Windows File Explorer or our Text Editor, not Perforce. So we come back here, we'll right-click once again and say New Text Document, and I'm going to call this thing f1.c.
And Windows is very kind and asks us if we want to make sure we got the right kind of file, because it will decide to open Visual Studio when we double-click on this to edit it, so we're going to go ahead and do that. In this case, f1.c is going to say main () printf With searching comes loss, and the presence of absence, My Novel\" not found. With Visual Studio we can simply click Save All, and that saves the file, and now we can switch back to Perforce and add it to the repository, come back to our workspace, refresh it once again, now we can see the file.
Once again we have a plain icon, we will right-click, Mark for Add, and then we'll Submit, and we'll say Initial Commit of f1.c. Once again, we can see all the command line operations down here in the log. Now, to see the history of what we've done so far, we can right-click on our p1 folder in the workspace and select Folder History. And now you can see the list of Changelists we've done with this folder.
Changelist 1 we created the p1 folder by adding the read me ReadMe. Changelist 2, we did an initial commit of p1. Unlike SVN and Git and Mercurial, Perforce is a locking version control system, so before we can edit this we have to check it out. You notice we have a green dot but we don't have anything that tells us we can edit it. So with Perforce you have to right-click here and say Check Out. Now you can also do Check Out and Open if you want to open with the default tools, so we'll just do that, Check Out and Open.
Once again, it opens Visual Studio. Now let's change My Novel to a more modern error message. We'll say Website not found. And we'll save it, and we'll Exit Visual Studio, and now you can see it shows here in the History that f1.c is pending a change, and let's save that file and check it in again. So once again, we'll do a Submit, and we'll say Change My Novel to Website and submit it.
Now we might want to look at the history of the file, so what we can do now is we can come down here and say File History, and over here, since we have the History window open, we can see that here's the file history of the file. So if we select these two lines together and say Diff Selected, it'll open up Diff tool and show us the changes we've just made. One of the cool tools that Perforce has is something called the Time-lapse View.
Now right now it's only going to show two different versions, but here is version 1, there's version 2, and if we had more-- which we'll see later--we'll actually be able to see the file as it changes over time. All right, now we're going to make one more change. Again, we're going to Check Out and Open, and we're going to change Website to Webpage, Save it and Exit Visual Studio. And now again, we're going to Diff this against what they call the Have Revision, which is the Head Revision, and you can see what's in the depot here. This is the depot side with the purple triangle as Website, and what we haven't checked in is web page.
But remember we have saved it, so now we're going to do is we're going to revert. We're going to right-click here and Revert. Now the Revert dialog says what are we going to revert. In this case, we're going to Revert our edit. We right-click here, and now if we go and Diff this against the Have version, you're going to see that it says Website in both cases because we've updated our workspace with the content that we had originally. All right, now we reverted to a particular version.
Now if we want to actually revert to a specific version, for example, we can come back here to the initial version and right-click on here and say Rollback to Revision. This is going to allow us to roll back to anything that we want to. So for example, we could roll back to the previous version, or we can roll back to a specific revision, we can roll back to a specific changelist, a Date and a Time or a Label. So you've got a very flexible manipulation of files within Perforce. So in this case, we're going to roll back to Revision 1, and they give you a predefined changelist description. We're going to run it, and now we're going just kind of come down here and Open this up and see that we're back to My Novel.
Now remember, all the different versions are still inside the repository. You haven't lost anything. So for example, if we come back here and we do another rollback, we can roll back to the Changelist, and we can browse for the Changelist and go all the way back to Change My Novel to Website and submit that. And now when we Open the file you can see we're back to Website.
So that's the basic workflow for using check-ins and check-outs and reversion and rollback in Perforce. Now let's move on to tagging, which is called labeling in Perforce, and see how we can use that.
Get unlimited access to all courses for just $25/month.Become a member
82 Video lessons · 101038 Viewers
61 Video lessons · 87827 Viewers
71 Video lessons · 71703 Viewers
56 Video lessons · 103586 Viewers
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.
Your file was successfully uploaded.