Arcade Türü Oyun Programlamayı ve Bilgisayar Bilimleri Öğrenin

Arcade Türü Oyun Programlamayı
ve Bilgisayar Bilimleri Öğrenin

Version Control

4.1 What is Version Control?

No serious development should be done without version control. In fact, version control is so important, many developers would argue that almost no development should be done without version control.

Version control allows developers to:

Version control saves untold time and headaches. It used to be that version control had enough of a learning curve that some developers refused to use it. Thankfully today's version control tools are so easy to use there's no excuse not to.

There are two main types of version control. The original version control systems were “centralized.” Subversion (SVN) is a very popular piece of software that supports this type of version control. The other type is a “Distributed Version Control Systems” (DVCS). There are two popular versions of DVCS in use today, Git and Mercurial. Either works fine, but for this tutorial we will standardize on Mercurial. Mercurial is sometimes also known as Hg. Get it? Hg is the symbol for Mercury. We programmers are a hilarious bunch.

If you are taking this as part of a Simpson College class with Dr. Craven, all the programs you write will be turned into grade using the Mercurial version control system. Even your worksheets will be turned in this way.

4.2 Software Needed

Video: Setting up SourceTree

Changes that you and other developers make to the code are stored in “code repositories.”

Just like the web can be browsed with different web browsers, Mercurial code repositories can be browsed with different clients. We'll use a client called SourceTree.

Download SourceTree from:

www.sourcetreeapp.com/

You can also follow along with the video tutorial to the right.

4.3 Forking Repositories

We'll start this class with a code repository that has already been created. The code is currently hosted on a website callded “BitBucket.” Go to BitBucket and sign up:

bitbucket.org/

Once you have signed up, go to the code repository that I've created:

bitbucket.org/pcraven/program-arcade-games-work

The next step is to create your own copy of my repository so that you can change it however you like. Your copy will be called a “fork” of my original code. So click the “Fork” button:

fig.fork
Figure 46.9: Fork Repository Button

BitBucket will ask for details about the fork. You can set your own name for the fork or use the same name. But I highly recommend making the fork private! Otherwise anyone can copy and look at your code. If someone copies your code they aren't learning anything and that's not good. See below for the settings I recommend:

fig.fork2
Figure 46.10: Fork Repository

4.4 Cloning Repositories

Now we need to tell SourceTree to clone the repository. Sometimes this can be done from the web by selecting the following:

fig.clone1
Figure 46.11: Copy Repository Address

If that doesn't work, copy the web address for this repository:

fig.clone1
Figure 46.11: Copy Repository Address

If cloning from the web worked you should be at the “clone” dialog box. If you are using the copy/paste method then start SourceTree and hit the Clone button. Then set up an empty folder to put your files in.

fig.clone
Figure 46.12: Clone Repository

Before it can start, it may ask you to enter your repository user name and password.

fig.repository_folder
Figure 46.13: Code Repository Folder

You can now open up this folder and edit the files like normal.

4.5 Committing Changes

When you have finished making a change, you can commit it to the code repository. Don't worry! The great thing about this type of commitment, is that you can go back on any “commit” that you make. Going back on a commitment is a feature with this software! How cool is that?

In the example below, I have changed the first file, deleted the second file, and added a third file. Notice how the icon is different. On the right side you can see exactly what was changed. To commit these changes, hit the “commit” button.

fig.changed_file
Figure 46.14: SourceTree after changes

This will bring up a commit dialog box. You can select what files will be committed, and add a comment. It helps to add a comment so that you can quickly find changes. I recommend committing each lab and worksheet separately. Once you've done that, hit “commit.”

fig.folder_icon_change
Figure 46.15: Commit Dialog

4.6 Pushing Changes to the Server

Commit at many times as you like. Each commit is only on your local computer. None of them are on BitBucket yet, and no one else can see them. When you are ready to move all your changes to the server, hit “push.”

fig.folder_icon_change
Figure 46.15: Push Menu Button

4.7 Pulling Changes

If you are only using one computer to code, you can stop here and not worry about pulling changes.

If changes have been done on a different computer, or though the BitBucket website, you need to pull those changes onto your computer. After that you will update to the new code or merge the code in with your own changes.

You can't push to the server until you've pulled down any updates first. This prevents you from overwriting someone else's code.

SourceTree will show the number of changes that are waiting to be pulled. In the figure below there are two changes waiting to be pulled:

fig.folder_icon_change
Figure 46.15: Pull Menu Button

After clicking “pull” you will see a summary of all the changes. Just click the “ok” button.

fig.folder_icon_change
Figure 46.15: Pull Menu Dialog

After that, you need to may need to merge your changes:

fig.folder_icon_change
Figure 46.15: Merging Changes

If the same line of code is edited in two different places, SourceTree will step you through manually merging the code.

4.8 Turning In Homework

Video: Turning In Homework

Once version control has been set up, follow the following steps to complete your homework and turn it in.

  1. In the program-arcade-games-work directory you cloned from the version control system, find the proper file and directory to complete your lab.
    fig.folder_icon_change
  2. Do the homework.
  3. Commit the files using SourceTree.
    fig.folder_icon_change
  4. Push the files using SourceTree.
    fig.folder_icon_change
  5. Go to BitBucket.org.
  6. Select your repository.
    fig.folder_icon_change
  7. Click the “Source” icon.
    fig.folder_icon_change
  8. Find the file or directory with your homework.
    fig.folder_icon_change
  9. Copy the URL.
    fig.folder_icon_change
  10. Go to ProgramArcadeGames.com.
  11. Click the “Progress” tab.
    fig.folder_icon_change
  12. Find the homework assignment to turn in.
    fig.folder_icon_change
  13. Paste the URL.
    fig.folder_icon_change
  14. Click “Send to be graded.”
  15. Check back later to review your grade.

You are not logged in. Log in here and track your progress.