Source Control Header.

What Does Source Control Do?

It's very easy to describe source control to a game developer. Source control is like a save system for your code. But it's the best most comprehensive save system ever created.

Saving over an old save in a game means it's gone forever. Not so with source control! Every time you save the code it's stored forever, to be revisited whenever you want. If you're hacking away on your game and suddenly seem to have broken everything then you can load an earlier save.

There are powerful tools to compare different "save" states, so it's easy to see what changes have occurred and root out any bugs. Source control can do many different things but the most important value proposition is this versioning system.

What Should I Use

Unless you're already familiar with a tool; just use Git. It's won the battle for the most used source control tool. This means:

  • There are more resources online
  • There are more tools
  • There are more people who'll be able to help you out
  • There are less bugs
  • It will work on your system without issue
  • Potential teams mates will be familiar with it

Should I use a GUI?

If you're more comfortable outside the command line than YES! Don't punish yourself doing it the most "geekish" way possible. You're not here to impress cynics on Hacker News, you're here use a tool to help you get stuff done.

Git is complicated

If you struggle to get it, don't worry, you are not alone. The user interface for Git is not friendly, but it's not impossible to learn. Just set aside some time, read some tutorials, watch some videos and play around with a test repository.

If that doesn't fix it, git.txt contains the phone number of a friend of mine who understands git. Just wait through a few minutes of 'It's really pretty simple, just think of branches as...' and eventually you'll learn the commands that will fix everything.


Common operations : GIT

Here are the more common operations to use, with the Git source control system. These are from the command line (for a nice GUI tool look up Source Tree).

How I start a new source control project?

Create a directory for the project, navigate to it, and run the following command.

git init

In general it's better to create a project on github or bitbucket and then clone it locally. That way you have a remote server to send changes to.

Output text for a git init command.

How do I see the last 5 commits?

git log --oneline -n 5


Output text for a git log command.

How do I switch to an earlier version?

git checkout 8358810

The argument is a hash. Use the check last 5 commits command to see the hashes.

How do I revert to an earlier version?

git checkout 6d9d27d .
git commit -m "Reverting to commit 6d9d27d"

The . at the end of the command is important. It tells git to revert the current dir. You should be in your Git checkout root when running this command.


Output text for a git revert command.

How do I undo my local changes?

git reset --hard HEAD

Let's say we've edited the test.txt file to say "Steve is a butt". We don't want to commit this, this was juvenile, we just want to get rid of the local changes. This head reset command helps us out.

Reverting local changes in git.

How do I undo changes I've just committed?

git reset HEAD~1

Reverting last commit in git.

Note that this removes the previous commit from the log. (It can be restored but you'll have to look up some new commands).

How do I remove a file from source control?

This is pretty easy. Remove the file by deleting it, add the changes and then commit the directory.

rm test.txt
git add .
git commit -m "Removed test"

Removing a file in git.

How do I permanently remove a file from source control?

!! Needs concrete example and screenshot. commit all, show nuclear_codes.txt, then remove

Committed the nuclear warhead test codes? Fear not it happens to us all. When you need to totally eradicate a file from the source control history here's the snippet you need.

git filter-branch --tree-filter 'rm -rf /path/to/file/or/folder' HEAD

How do I rename a file?

As your code grows names changes. Here's how to update the names of file.

git mv goodbye.txt
git commit -m "Renamed file"
git push origin master

This command will also work for directories!

How do I tell source control to ignore a file type?

This needs to be run from the root of your git repo.

echo '.DS_Store' >> .gitignore

You don't have to this from the command line, feel free to open up the .gitignore file and add ignore rules manually.

How do I setup my existing project on a new computer?

You need use clone command. If you're just starting out with git you're probably using github so here's the example for that.

git clone[username]/[project name].git

Or bitbucket

git clone[username]/[project_name].git

How do I correct my last commit message?

This happens to us all, we write a commit message, check it and notice a typo or error.

git commit --amend -m "Updated commit message"

This line will change the last commit message to "Updated commit message".