24
IMGD Perforce Guide draft, 20150208 What Is Perforce? Perforce is a version control system meant to help teams of programmers, artists, composers and designers work together. You can think of it as a cross between Apple Time Machine and Google Docs. Like Time Machine, it saves a copy of each version of a particular file, so it’s easy to recover from errors or view past versions. Like Google Docs, it is a central file server that is accessible to everyone on a team so that they can all work on the same files. There are a few key concepts to understand in using version control, as well as some special vocabulary. (Note: if you prefer visual explanations, you may like this .) First, the central server is usually called the repository (sometimes abbreviated to “repo”). It stores every version (also known as a revision) of every document. Team members get files from the repository by checking out or getting the ones they need. Team members put files into the repository or update them by checking in, committing, or submitting. (Some version control systems also have a step called push.) When new or changed files are submitted, the server automatically saves them with a time stamp so that it knows which version is the latest. Anyone who needs the latest version of the project as a whole can just ask for the latest revision of everything in the repository. In order to check out or submit files to the server, you need to install a special program, referred to as a client. This term just means “not the server but the application that talks to the server.” In Perforce the client is called P4V. When we need to distinguish between files on the server and files on your computer, we often use the word remote to mean what’s on the server and local to mean what’s on your computer. Perforce has some unique features and uses some special terms for them. They call the central server a depot, although we generally use this interchangeably with repository. The client software manages what is called a workspace, which is where we specify which folders on the server correspond to which folders on our computer. Perforce has two different ways of getting files from the server. The first is just getting the files, which makes copies of them on your computer. The second is

IMGD Perforce Guide - m3thinks.comm3thinks.com/usc/ctin483/IMGDPerforceGuide2015-08-08.pdf · IMGD Perforce Guide ... Next you will be asked to log in. Enter your USC NetID as the

  • Upload
    halien

  • View
    234

  • Download
    2

Embed Size (px)

Citation preview

Page 1: IMGD Perforce Guide - m3thinks.comm3thinks.com/usc/ctin483/IMGDPerforceGuide2015-08-08.pdf · IMGD Perforce Guide ... Next you will be asked to log in. Enter your USC NetID as the

IMGD Perforce Guide draft, 2015­02­08

What Is Perforce? Perforce is a version control system meant to help teams of programmers, artists, composers and designers work together. You can think of it as a cross between Apple Time Machine and Google Docs. Like Time Machine, it saves a copy of each version of a particular file, so it’s easy to recover from errors or view past versions. Like Google Docs, it is a central file server that is accessible to everyone on a team so that they can all work on the same files. There are a few key concepts to understand in using version control, as well as some special vocabulary. (Note: if you prefer visual explanations, you may like this.) First, the central server is usually called the repository (sometimes abbreviated to “repo”). It stores every version (also known as a revision) of every document. Team members get files from the repository by checking out or getting the ones they need. Team members put files into the repository or update them by checking in, committing, or submitting. (Some version control systems also have a step called push.) When new or changed files are submitted, the server automatically saves them with a time stamp so that it knows which version is the latest. Anyone who needs the latest version of the project as a whole can just ask for the latest revision of everything in the repository. In order to check out or submit files to the server, you need to install a special program, referred to as a client. This term just means “not the server but the application that talks to the server.” In Perforce the client is called P4V. When we need to distinguish between files on the server and files on your computer, we often use the word remote to mean what’s on the server and local to mean what’s on your computer. Perforce has some unique features and uses some special terms for them. They call the central server a depot, although we generally use this interchangeably with repository. The client software manages what is called a workspace, which is where we specify which folders on the server correspond to which folders on our computer. Perforce has two different ways of getting files from the server. The first is just getting the files, which makes copies of them on your computer. The second is

Page 2: IMGD Perforce Guide - m3thinks.comm3thinks.com/usc/ctin483/IMGDPerforceGuide2015-08-08.pdf · IMGD Perforce Guide ... Next you will be asked to log in. Enter your USC NetID as the

checking out files. This too makes copies on your computer, but it also locks the files on the repository so that no one else can change them while you are working on them. When we want to submit files to the repository, we first need to put them in a temporary holding area called a changelist. The changelist is a list of files that we want to be added, deleted or updated on the server. We first collect all of our changes in the changelist, and then we submit the changelist to the server.

Setting Up A Workspace The first thing you’ll need to do in order to use Perforce is make sure you have a copy of P4V on the computer you’re working on. The lab computers in SCA and SCI all have P4V installed already. If you need to download P4V for your own computer, go to this page: http://www.perforce.com/downloads/Perforce/Customer IMPORTANT: do not download the first thing you see on that page. Instead, click the Clients tab. At the top of the page you’ll see P4V: Visual Client. The page tries to guess what version you want, and it is nearly always wrong. Make sure that your platform (Mac or Windows) and version (10.7, 32­ or 64­bit, and so on) are correct. Then choose Accept and Continue. You may see a pop­up asking you to register; you can skip it. Your download should then begin. When it’s finished, run the installer.

Server Connection Settings When you run Perforce for the first time, it will put you into a setup wizard. On the first screen, enter these settings: Host: perforce.sca.usc.edu Port number: 1666

Page 3: IMGD Perforce Guide - m3thinks.comm3thinks.com/usc/ctin483/IMGDPerforceGuide2015-08-08.pdf · IMGD Perforce Guide ... Next you will be asked to log in. Enter your USC NetID as the

Log In Next you will be asked to log in. Enter your USC NetID as the user account. Then click the Next button at the bottom of the dialog (not the Browse… button that’s next to the user account.)

You will then be asked for a password. Your password will be the one you use to log into lab computers. If you have never used a lab computer, it will be your 10­digit USC id number. If you receive an error (such as “User ‘ttrojan’ not found”) or if Perforce does not accept your password, contact Creative Technology & Support ([email protected]) to make sure your account has been set up.

Create Workspace Next Perforce will ask you to choose an existing workspace or create a new one. Click the radio button next to Create a New Workspace. For the workspace name, use coursecode­yournetid (e.g. ctin483­ttrojan). Then choose the location where your workspace folder will be created. If you are on a lab computer, consider putting your workspace folder on your home drive so you can get to it from any lab station.

Page 4: IMGD Perforce Guide - m3thinks.comm3thinks.com/usc/ctin483/IMGDPerforceGuide2015-08-08.pdf · IMGD Perforce Guide ... Next you will be asked to log in. Enter your USC NetID as the

As an example, these settings:

will create a new folder like so: /Users/ttrojan/Perforce/ctin483­ttrojan Be sure that your Location (the lower text field) ends with a / (forward slash). Click the Next button.

(Don’t) Add Files to Workspace P4V will then ask you if you want to go ahead and get everything in the repository. Say no; we will get them in the next section.

Page 5: IMGD Perforce Guide - m3thinks.comm3thinks.com/usc/ctin483/IMGDPerforceGuide2015-08-08.pdf · IMGD Perforce Guide ... Next you will be asked to log in. Enter your USC NetID as the

Click Next, and P4V will show you a last dialog confirming your settings. Click Finish or Done and you’ll see the main P4V window.

Tweaking Workspace Settings: Workspace Mappings P4V’s default settings for a new workspace are not generally what we want at IMGD. We will want to tweak a few of them: the Workspace Mappings, the Host, and a setting called Modtime. All of these settings can be changed in one dialog. First we will need to look at the depot to see the details of what course, semester and section you need. Click the Depot tab on the left side of the window:

You should see something like this:

The details will depend on which course you’re taking and when. Take note of the path to the Course Materials folder. In the screenshot here the path is ctin_483/20151/18355/ From P4V’s main window, choose Connection­>Edit Current Workspace…

Page 6: IMGD Perforce Guide - m3thinks.comm3thinks.com/usc/ctin483/IMGDPerforceGuide2015-08-08.pdf · IMGD Perforce Guide ... Next you will be asked to log in. Enter your USC NetID as the

You will see a dialog like this one. (You may need to click the disclosure arrow next to Workspace Mappings: to see the bottom part.)

First click on the button that looks like this: This will make the bottom pane show your workspace mappings as text rather than a hierarchy of folders.

Next, add text similar to what is in the screenshot: //ctin_483/20151/18355/… //ctin483­ttrojan/…

The slashes and …s are important, so be sure to follow the example text carefully. The part on the left should reflect the path you found in the last step. Why did we change the mappings? This change gets rid of some unnecessary folders on your computer, saving you a lot of clicking later on. The folders on your computer will look like this: /Users/ttrojan/Perforce/ctin483­ttrojan instead of this: /Users/ttrojan/Perforce/ctin483­ttrojan/20151/18355 Leave the dialog open and proceed to the next step.

Tweaking Workspace Settings: Host and Modtime Next we will change the Host and Modtime options. Why? Having anything in the Host field means that this workspace will only work on one computer (and sometimes not even then, if you are carrying your computer around and changing wireless networks). Modtime makes it so that the last­changed date on the files in your workspace reflects when they were last changed rather than

Page 7: IMGD Perforce Guide - m3thinks.comm3thinks.com/usc/ctin483/IMGDPerforceGuide2015-08-08.pdf · IMGD Perforce Guide ... Next you will be asked to log in. Enter your USC NetID as the

when you checked them out. This makes it easier to tell which revision of a file you have. These settings are under the Advanced tab in the same dialog (Edit Current Workspace…). Click on the Advanced tab now:

Take a moment to feel Advanced.

Delete anything in the Host field, and check the box next to Modtime.

Click OK and you’re done setting up your workspace!

Page 8: IMGD Perforce Guide - m3thinks.comm3thinks.com/usc/ctin483/IMGDPerforceGuide2015-08-08.pdf · IMGD Perforce Guide ... Next you will be asked to log in. Enter your USC NetID as the

The Perforce Interface Your main P4V window looks something like this:

Let’s look at the different areas.

Buttons

Refresh updates your view of both what’s on the server and what’s on your computer. You’ll probably use this a fair amount, because Perforce doesn’t notice changes particularly quickly. Get Latest takes whatever folder you’ve selected on the left side of the screen (in the example it’s /Users/ttrojan/Perforce/ctin483­ttrojan) and pulls down anything on the server that is newer than what you have. When you’ve been working on a project with a team, this will sometimes fail; see Conflicts below.

Page 9: IMGD Perforce Guide - m3thinks.comm3thinks.com/usc/ctin483/IMGDPerforceGuide2015-08-08.pdf · IMGD Perforce Guide ... Next you will be asked to log in. Enter your USC NetID as the

Submit takes whatever you have marked as ready to go the server (i.e. your changelist) and submits it to the server. Here too you may eventually encounter conflicts; see the Conflicts section below. Checkout tells the server to put a lock on whatever files you’ve selected. While you have files checked out, other team members may change them, but no one else can submit changes to the server. This can help to prevent conflicts when you are working on a team; it is also necessary in order to edit existing files. Add lets you add new files to the set of files that Perforce is managing. Notice that you can create new files in your workspace folder anytime, but they won’t make it to the server unless you explicitly add them in Perforce. Delete does the opposite; it removes a file from the set of files Perforce is managing and also tells the server to delete it. As with Add, Perforce doesn’t notice if you delete a file using the Finder or Explorer, and in fact this makes it impossible for you to tell Perforce to delete it. So you will always delete files from within Perforce. Revert looks like it does something useful, but it doesn’t. We’ll see how (and why) to revert files later.

The Depot/Workspace Pane On the left side of the window is the Depot/Workspace pane. (You may not have any files in your workspace yet; that will be covered below.)

This pane shows either what’s on the depot (server) or what’s on your computer. Because Perforce’s job is to sync files between the server and your computer, these will usually look very similar. IMPORTANT: When you are using P4V, pay close attention to whether you are looking at the Depot or Workspace tab. This is probably the most frequent cause of errors using Perforce. The buttons at the top right allow you to sort or filter the files you’re looking at.

Page 10: IMGD Perforce Guide - m3thinks.comm3thinks.com/usc/ctin483/IMGDPerforceGuide2015-08-08.pdf · IMGD Perforce Guide ... Next you will be asked to log in. Enter your USC NetID as the

The Details Pane The right side of the P4V main window is called the Details Pane, the Spec Pane, or just the Work Area. When the Files tab is selected, it shows details about whatever you’ve selected on the left side. The lower pane can also show who has checked out the file.

If you click on the Pending tab, you will see information about what you’ve prepared to send to the server.

We will return to this tab when we talk about submitting files. But there are a few important things to note. First, this pane shows a list of what Perforce calls changelists. A changelist is a set of files that you have created, containing things to add, delete, or update on the server. You will generally only use the default changelist. Second, notice the Filter description at the top. Perforce can show you details about changelists created by anyone connected to the same server. (This is meant to help large teams coordinate changes.) By default, however, it will only show your own. This is pretty much always what you’ll want, but if you

accidentally remove the filter (by clicking the button), you can restore the

Page 11: IMGD Perforce Guide - m3thinks.comm3thinks.com/usc/ctin483/IMGDPerforceGuide2015-08-08.pdf · IMGD Perforce Guide ... Next you will be asked to log in. Enter your USC NetID as the

filters. To do this, click on the disclosure arrow next to Filter:. Click the down arrow on the right side next to the User and Workspace fields and choose Current User and Current Workspace.

The Log Pane Finally, the bottom of the window is the Log Pane. When you start to use Perforce, you will see messages here regarding adding files, submitting them, and various other activities. IMPORTANT: Pay attention to log messages; sometimes they are the only indication that something didn’t work.

Managing Files in Your Workspace Getting Files from the Server In this section we will learn how to get things from the server. It is a pretty straightforward process. We will start by downloading the materials that your instructor has put up for your course. First, make sure you are looking at the Depot in the Depot/File Pane. Navigate to your course’s Course Materials folder. Select it and click the Get Latest button.

You may see a progress bar, depending on how much is in the folder. When Perforce is finished getting the files, you will see a message in the Log Pane saying how many files it downloaded (“added” in Perforce parlance).

Page 12: IMGD Perforce Guide - m3thinks.comm3thinks.com/usc/ctin483/IMGDPerforceGuide2015-08-08.pdf · IMGD Perforce Guide ... Next you will be asked to log in. Enter your USC NetID as the

Now let’s look at the folder called Workspace. Note that this is not the same thing as the “workspace” you set up earlier. It’s just a folder that happens to be called “Workspace” because it is meant to hold student work. It likely has a lot of subfolders, for student work areas, turn­ins, and so on. If you’re setting things up at the beginning of a semester, you can go ahead and select it and Get Latest. You’ll get all the folders and subfolders inside Workspace, each with an empty file called placeholder.txt. Why do you need all these empty folders? It’s because Perforce only knows how to sync files when they are in the same place on your computer and on the server. For example, the only way to turn something in in this folder on the server: …/Workspace/_TURN_IN/Week02/ is to get the Week02 folder onto your computer: [Your workspace root]/Workspace/_TURN_IN/Week02/ and then put your file into it. We will go over how to add and submit files in the next section.

Removing Unwanted Files from Your Computer Let’s say you’re setting up your workspace a few weeks into the semester, and you don’t need to have everything that everyone has uploaded. There are a couple of different ways to do this: you can get everything and then remove what you don’t want on your computer, or you can try to grab just the folders, which is covered in the next section. Why can’t we just delete the files by putting them in the computer’s Trash or Recycling Bin? Because it will confuse Perforce and cause a lot of error messages. See the section on deleting things from the server, below. For the get­all­and­prune method, first Get Latest with the Workspace folder selected. This will probably take a few minutes while it pulls down everything in the folder. When it’s done, go to the Workspace tab and you’ll see all the new stuff. Select each thing you don’t want (you can shift­select several files at once if needed). Then choose Actions­>Remove from Workspace. This will delete the copies of the files that are on your computer, but will leave everything on the server untouched. It also makes sure that you won’t accidentally download them again the next time you Get Latest, because you’ve told Perforce you don’t care about them.

Page 13: IMGD Perforce Guide - m3thinks.comm3thinks.com/usc/ctin483/IMGDPerforceGuide2015-08-08.pdf · IMGD Perforce Guide ... Next you will be asked to log in. Enter your USC NetID as the

Getting Folders from the Server If you want to put anything into Perforce (homework, projects, etc.), what you will need from the server is the folder structure, so that you can save files to the right places in your workspace. But here there is a wrinkle: Perforce does not see folders directly; it only sees files. If they happen to be in a folder, then the folder will come along when you Get Latest. But you can’t just check the folder out on its own. So if you want the folder, you need to get at least one file inside it. (The same is true if you want to add a folder – there has to be at least one file in it.) This is why there are placeholder.txt files all over the repository. To get a folder on the repository without getting all of its contents, select the placeholder.txt file inside it and Get Latest. The file, its containing folder and all of its parent folders will be created on your computer, but no other files will come along.

Adding and Submitting Files Let’s try submitting a file. If you haven’t already gotten the Workspace/_TURN_IN folder and its subfolders from the server, go back to the last section and do that first. Adding a file takes three steps:

1. Save the file to a folder in your workspace on your computer. 2. Tell Perforce you want to add the file on the server. 3. Submit.

First, make a simple text file on your computer (.rtf, .txt, or similar). Call it something like ttrojan­practice.txt and save it in this folder on your computer: [Your workspace root]/Workspace/_TURN_IN/Practice Area/ In the example we’ve been using, this would be /Users/ttrojan/Perforce/ctin483­ttrojan/Workspace/_TURN_IN/Practice Area/

Go back to Perforce and select the Workspace tab on the left. Navigate to the folder where you just saved your file and click the Refresh button. You should see your file appear.

Page 14: IMGD Perforce Guide - m3thinks.comm3thinks.com/usc/ctin483/IMGDPerforceGuide2015-08-08.pdf · IMGD Perforce Guide ... Next you will be asked to log in. Enter your USC NetID as the

Now we will tell Perforce that we want to add the file to the corresponding folder on the server. To do this, select the file and click the Add button.

You may see a dialog like this. You’re not likely to need anything but the default changelist until you’re a Perforce pro, so check the box at the bottom and click OK.

Look down in the Log pane. You should see a message like this:

Now look at the Pending tab and make sure your file was added to the changelist. You may need to click the disclosure arrow next to default.

Notice that the file path it is showing is where your file will go on the server. Make sure it’s correct (you’re turning in your homework in this week’s folder, etc.) Next, we need to tell Perforce to take our changes (in this case just adding a file) and submit them to the server. The most error­proof way to do this is to double­click on the word default. It is also possible to use the Submit button, but make sure you have selected the whole changelist and not just one file. When you’ve double­clicked or used the Submit button, you will see this dialog. The Submit button in the dialog will be dimmed until you type something, so write a short message explaining what you are submitting. Then click Submit.

Page 15: IMGD Perforce Guide - m3thinks.comm3thinks.com/usc/ctin483/IMGDPerforceGuide2015-08-08.pdf · IMGD Perforce Guide ... Next you will be asked to log in. Enter your USC NetID as the

You’re almost done. The last step is to make sure everything worked.

First, look down in the Log pane. You should see a message like the one on the left.

Next, click on the Depot tab and navigate to the folder where your new file should be. Make sure you see your file on the server.

Deleting, Undeleting, and Moving Files IMPORTANT: Because of how our Perforce server is set up, it is possible for you to move or delete someone else’s work. Once something is on the server, it is impossible for you to delete anything completely, so accidental deletions are not a catastrophe. But please be careful.

Deleting Files At some point in your relationship with Perforce, you will add and submit a file, and then later decide you don’t need it anymore. Or perhaps you submitted a file with the wrong name. Perforce allows you to delete the file from your computer and have it disappear from the repository (although it is never actually erased, because all of its revisions will still be there.) IMPORTANT: If you need to delete files, you must delete them using P4V. Deleting a file is much like adding a file, but you must delete files from inside Perforce. If you drag them to the trash (or delete them from another program, like Unity), Perforce gets confused. It will still look for them every time you Get Latest or Check Out the folder where they used to live, and you will get numerous angry red error messages that say something like this:

Page 16: IMGD Perforce Guide - m3thinks.comm3thinks.com/usc/ctin483/IMGDPerforceGuide2015-08-08.pdf · IMGD Perforce Guide ... Next you will be asked to log in. Enter your USC NetID as the

chmod: /Users/ttrojan/Perforce/ctin483­ttrojan/FileThatYouDeleted.txt: No such file or directory So the first step is to open or switch to P4V. From either the Depot or the Workspace tab on the left, select the file you want to delete. Make sure it is a file you own, not someone else’s. With the file (or files) selected, click the Delete button. Look at your changelist under the Pending tab. You should see your file there with a tiny red x next to its icon. This means that you have told Perforce you want to delete the file. But just like when you add files, Perforce does not actually delete the file yet. To do that, you need to submit the changelist, following the same steps you used in the last section.

Canceling a Deletion Before You Submit If you realize you didn’t mean to delete a file, you can remove it from the changelist and no one will ever know the difference. To do this, go to the Pending tab and select the file. Choose Actions ­>Revert. You’ll see a dialog like this one. Here, Revert does not do anything to the file’s contents. It refers to (and undoes) the act of marking the file for deletion. The same technique also lets you change your mind about adding files. Note that clicking the Revert button does not accomplish the same thing. You must choose Revert from the Actions menu, or use its keyboard shortcut (Command­R or Control­R). Again, this does not change anything about the files; it just lets you change your mind about adding or deleting them. (Reverting a file you’ve edited is different; see below.) If you fail to notice your mistake before you’ve submitted the changelist, there is still hope – look in the section on Traveling Back in Time below.

Page 17: IMGD Perforce Guide - m3thinks.comm3thinks.com/usc/ctin483/IMGDPerforceGuide2015-08-08.pdf · IMGD Perforce Guide ... Next you will be asked to log in. Enter your USC NetID as the

Moving and Renaming Files It is possible to get lost in all the folders on the repository, and you may realize you’ve put something in the wrong place or saved it with the wrong name. Luckily, moving and renaming files is not too difficult. Let’s take a scenario where you have saved a file in the wrong week’s turn­in folder, and also given it a name that doesn’t match what the instructor wants. (Perhaps you were very tired, or overwhelmed with the excitement of completing the assignment.) As with deletion, it is necessary to move and rename files within Perforce so that it doesn’t get confused. So the first step, again, is to open or switch to P4V. Then find the stray file in the Workspace tab.

Perhaps you put your Week 3 homework into Week 2, and gave it a rather silly name as well. We can fix both problems in a single dialog!

Choose Actions­>Rename/Move… (It’s close to the bottom of the menu.) You’ll see this dialog:

You can type in a new name, browse to a new location, or both. Make sure to change the dropdown to your default changeset to avoid confusing yourself. If the file is not part of a Unity project (e.g. a text file or build for homework), you can submit your changes right away. Choose Submit… and proceed with the Submit dialog as usual.

If the file is part of a Unity project, you will need to let Unity update its internal file­tracking so that it doesn’t get confused. So, in the Rename/Change dialog, click Save to Changelist. Open your project in Unity, or if it’s already open switch to it. Unity will automatically do what it needs to do, which involves updating the YourFile.meta file that lives next to YourFile. Then you can return to Perforce, make sure the .meta file is in your changeset, and submit.

Page 18: IMGD Perforce Guide - m3thinks.comm3thinks.com/usc/ctin483/IMGDPerforceGuide2015-08-08.pdf · IMGD Perforce Guide ... Next you will be asked to log in. Enter your USC NetID as the

Interlude: What’s the Point of Perforce? All this adding, deleting and moving is useful, but we haven’t really done anything that we couldn’t do in Google Drive or iCloud or Dropbox. As we’ll see in the next section, the power of version control systems is that they help teams work together on the same set of files without constantly getting in each other’s way or breaking things. So do you only need version control when you are working on a project with other people? Actually, no. If you have a project of any appreciable size, and particularly if you are new to writing code, version control provides a vital safety net while you are working. As long as you check your files in frequently, you will always be able to get back to an earlier version. This takes the pressure off of you when you are coding, because you know you can recover if something gets hopelessly broken. Using Perforce effectively in a game project, e.g. with Unity, is outside the scope of this document. But we can look at individual processes you would need, like checking out files and rolling back to earlier versions.

The Problem of Conflict So you’ve mastered turning in a simple text file in the right place with a proper name. Now let’s say you want to design a poster with a friend using Adobe Illustrator. When more than one person is working on a single file during a project, you are very likely to encounter the problem of conflict. This doesn’t refer to arguing with your collaborators; it is a name for what happens when you make independent changes to the file at the same time. Let’s say you both start from a draft poster made by your friend, and you agree on some things that need to be done: changing the headline text, rearranging the layout, tweaking some vector art. Then you both go home. You start working on the vector art, because you’re in the mood for Bézier curves. As you tweak and polish, you realize the whole thing needs to be bigger if you want anyone to understand what it is. So you rearrange some nearby text. Meanwhile, your friend starts working on the layout and decides that the graphic works best in a totally different place on the page. When you get back together, you realize you have a problem: there’s no easy way to get both changes into one file. You will basically have to open one

Page 19: IMGD Perforce Guide - m3thinks.comm3thinks.com/usc/ctin483/IMGDPerforceGuide2015-08-08.pdf · IMGD Perforce Guide ... Next you will be asked to log in. Enter your USC NetID as the

person’s file and manually reproduce any changes you want from the other person’s work. This might not be so bad if you were both working on a simple text file – you could see which parts were different and use copy and paste to reconcile them. But this is not so easy with an Illustrator file – if there are a lot of small changes, you’ll just have to remember what they were if you want to recreate them. We are using an Illustrator file as an example because its file format is binary, that is, any file that is not plain text. While version control systems are usually smart enough to notice and help resolve conflicts in text files, there is simply no way to get the differences between two binary files in a meaningful way. Thus, systems like Perforce have built­in mechanisms to help prevent these conflicts from happening in the first place.

Working on Existing Files in Perforce Checking a File Out In Perforce, when you want to work on a file that’s already been added to the server, you must first check it out. This does two things: it copies the file (usually the latest version) to your computer, and it sets a lock on the server so that no one else can submit changes. (They can still check it out and make changes, though – we’ll discuss this next.) So the first step to making changes is to find the file in the Depot tab. Select it and click the Checkout button. If the Checkout button is dimmed, you may need to Get Latest first. Perforce will automatically add the file to your default changelist, and put a very tiny red checkmark next to the file’s icon. In the Log pane you should see a message like this:

Now you can open the file and make your changes. This might mean editing the file in Illustrator or Word, or replacing a Unity build file with a newer, better build. As long as a file with the same name ends up in the same folder, Perforce doesn’t care how you changed it. When you are finished, save your work and return to P4V. All you have to do now is submit your changelist as you’ve seen in previous sections. This will put the new version onto the server and also release the lock so that others can change the file.

Page 20: IMGD Perforce Guide - m3thinks.comm3thinks.com/usc/ctin483/IMGDPerforceGuide2015-08-08.pdf · IMGD Perforce Guide ... Next you will be asked to log in. Enter your USC NetID as the

IMPORTANT: Once you check out a file, you must either submit your changes or throw them all away. If you try to remove them from your changelist by reverting (as you do when deleting or adding files), Perforce will replace your local copy of the file with the latest from the server, clobbering any changes you have made. One consequence of this is that you can’t submit anything else until you finish (or throw away) your changes. If this causes a problem, you can investigate using multiple changelists, but that is beyond the scope of this document.

Preventing and Resolving Conflicts Despite the lock system, it is still possible for team members to end up with conflicts. For example, consider this sequence:

1. You check out AwesomePoster.ai from the server. The server puts a lock on the file.

2. Your friend checks out AwesomePoster.ai from the server. 3. You and your friend each make changes. 4. You submit your file, and the server removes the lock. 5. Your friend submits the file, and the server rejects it because it is based

on a version older than the current one. To prevent this, it is best to apply an exclusive lock when you are working on binary files. Doing this involves one extra step: immediately after you check the file out, choose Actions­>Lock (Command­L or Control­L). As long as you have the file exclusively locked, Perforce will not allow anyone else to check it out. When you submit the files, Perforce automatically removes the lock. Be sensitive about using locks. They are meant to help prevent conflicts, but if you forget to submit your work, you may be keeping other people from doing their jobs. When you are working on text files, such C# scripts, it is not necessary to use an exclusive lock because Perforce provides a powerful tool (P4Merge) for resolving conflicting revisions. Go ahead and download it here: www.perforce.com/product/components/perforce­visual­merge­and­diff­tools That page also has a few tutorial videos showing different ways you can use P4Merge. Future versions of this document may also cover using P4Merge in greater detail.

Page 21: IMGD Perforce Guide - m3thinks.comm3thinks.com/usc/ctin483/IMGDPerforceGuide2015-08-08.pdf · IMGD Perforce Guide ... Next you will be asked to log in. Enter your USC NetID as the

Traveling Back in Time Seeing and Getting Older Revisions of a File As explained above, Perforce provides an important safety net for teams and for beginning developers, because it lets you go back to earlier revisions if things get too messed up to fix. To do this, we will use a new tool: the History tab. Open the History tab by choosing View­>History. Select a file in the left pane. You will see something like this in the right pane: This file has had a number of revisions as we’ve tried out different things in Perforce, and each one that was submitted to the server is shown here. There are two things you might want to do from here. You might just want to look at the previous versions of a file (e.g. to remember when you made a particular change, or to copy a single line of code). Or you might regret the things you’ve done to it recently, and want to return to a better time. To see what a file looked like at a particular revision, you can choose the Preview tab in the bottom half of the pane, or double­click the file’s name to open it in the corresponding application (Mono, Photoshop, etc.) You can also compare one version of a text file directly with another in P4Merge. To do this, click on one of the revisions you care about, then drag it onto the other.

Page 22: IMGD Perforce Guide - m3thinks.comm3thinks.com/usc/ctin483/IMGDPerforceGuide2015-08-08.pdf · IMGD Perforce Guide ... Next you will be asked to log in. Enter your USC NetID as the

P4Merge will open the two files side­by­side and highlight the differences in the text.

If you’d like to pull down a particular revision (perhaps you are testing each version until you find one that isn’t broken), select it in the History view. Choose Actions­>Get Revision… You will see a dialog like this:

The second radio button will be selected and you will see the revision number you chose in the text field to the right. If this is what you want, click Get Revision.

Getting an older version of a file does not delete anything from the repository – all your work is still there, safe and sound. However, you cannot make any changes to this older version of the file, because that would create a conflict. You can either choose Get Latest to go back to working on the latest version, or decide to roll back to the earlier version.

Rolling Back a File We all wish we could undo our actions sometimes. As long as you’ve been careful to check your work in frequently, Perforce will let you turn back time. If you want to start over from an earlier version, first select the file in the History view and then choose Actions­>Rollback… This brings up the following dialog.

Page 23: IMGD Perforce Guide - m3thinks.comm3thinks.com/usc/ctin483/IMGDPerforceGuide2015-08-08.pdf · IMGD Perforce Guide ... Next you will be asked to log in. Enter your USC NetID as the

This looks like a combination of the Get Revision… and Rename/Move dialogs, and that’s pretty much how it works. The revision you selected will be pre­filled in the text field, and you can either submit your rollback right away or save it and submit it later. What does this do? As before, it does not delete anything from the server. The revisions you submitted before rolling back are still there. What this command does is make a copy of your chosen revision and put it into the “latest” slot in the repository. This allows you to check it out and work on it as usual. If you change your mind again, you can still get any revision you want using the Get Revision process above.

Undoing a Deletion Undoing a deletion is a little bit different from going back to an earlier revision. Perforce thinks of deleting a file as making a revision to the folder that contains it. While Perforce will let you select individual files to revert, you can only undo a deletion by telling Perforce to revert changes to the whole folder. If you made a bunch of other changes to files in that folder in the meantime, they will be (temporarily) undone. The first step is to select the folder that used to contain the file. Perforce will show you the history of all the changelists that involved files in the folder, including the one where you deleted the file that you want to recover.

Page 24: IMGD Perforce Guide - m3thinks.comm3thinks.com/usc/ctin483/IMGDPerforceGuide2015-08-08.pdf · IMGD Perforce Guide ... Next you will be asked to log in. Enter your USC NetID as the

Choose the changelist immediately before the one where you deleted the file. Then choose Actions­>Get Revision… It will look the same as it did in the last section, except that it will have populated a changelist number rather than a revision number.

Click Get Revision and Perforce will revert the folder to its state as of your chosen changelist, including restoring any deleted files. Note that this only changes what’s on your computer. To get the server to see the revived file, select it, click the Add button, and submit it to the repository.