Things I can’t remember – Git

In git you clone a project—not checkout like in Subversion. You’ll probably want to put it in a directory that has a name that is the same as the project (or related to the project name).


$ git clone git://github.com/hubuser/importantProject.git importantProject

If you are hosting your own git server, you’ll probably use something like this.


$ git clone username@yourdomain.com:/www/importantProject/ importantProject

Once you’ve cloned the repository you’ll have the exact same files and file structure as the original. You’ll also be in the master branch.


$ git status
On branch master
Your branch is up-to-date with 'origin/master'.

nothing to commit, working directory clean

You’ll also get a .git directory with the following files.


$ cd .git
total 28
-rw-r--r--   1 username  staff    23B Jun  2 09:31 HEAD
drwxr-xr-x   2 username  staff    68B Jun  2 09:31 branches/
-rw-r--r--   1 username  staff   312B Jun  2 09:31 config
-rw-r--r--   1 username  staff    73B Jun  2 09:31 description
drwxr-xr-x  11 username  staff   374B Jun  2 09:31 hooks/
-rw-r--r--   1 username  staff   8.8K Jun  2 09:34 index
drwxr-xr-x   3 username  staff   102B Jun  2 09:31 info/
drwxr-xr-x   4 username  staff   136B Jun  2 09:31 logs/
drwxr-xr-x   4 username  staff   136B Jun  2 09:31 objects/
-rw-r--r--   1 username  staff   107B Jun  2 09:31 packed-refs
drwxr-xr-x   5 username  staff   170B Jun  2 09:31 refs/

Now suppose I modify my robots.txt file.


$ git status
On branch master
Your branch is up-to-date with 'origin/master'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

  modified:   robots.txt

no changes added to commit (use "git add" and/or "git commit -a")


$ git diff
diff --git a/robots.txt b/robots.txt
index 90098a4..3aa5532 100755
--- a/robots.txt
+++ b/robots.txt
@@ -1,3 +1,5 @@
 # robots.txt for http://www.rememo.info/

 User-agent: *
+Disallow: /order/
+

Before we commit the file, we need to stage it. The status command above tells you how to to it.


$ git add robots.txt

We can see the staged changes with:


$ git diff --staged
diff --git a/robots.txt b/robots.txt
index 3aa5532..abd2889 100755
--- a/robots.txt
+++ b/robots.txt
@@ -3,3 +3,4 @@
 User-agent: *
+Disallow: /order/


Now $git diff returns nothing because there are no unstaged changes.

We can add and commit it in one command.


git commit -a
[master 4623ad2] Added a disallow
 1 file changed, 2 insertions(+)

Alternatively, you can combine the commit with the message.


git commit -a -m "Added a disallow"
[master 4623ad2] Added a disallow
 1 file changed, 2 insertions(+)

You can remove files from the repository by deleting them from your work area. They will show up in the unstaged area or you git status output. You can also use git rm to remove a file.

Likewise you can rename a file with mv originalName newName and git will notice. Or you can use git mv originalName newName.

You can view the commits that you have made with git log.


$ git log
commit 4623ad2cbe4163e2d013c7e53728023e4d7163e6
Author: User Name < username@WellGolly.com >
Date:   Tue Jun 3 07:55:00 2014 -0700

    Added a disallow

commit 065b7362f9ad19d6e2fe69cde9629abf0beabb95
Author: User Name < username@WellGolly.com >
Date:   Mon Feb 24 09:00:03 2014 -0800

    Changed site name and added blank line at end of files

commit 61277e4d12636044e9b873608c325470d98577e0
Author: User Name < username@WellGolly.com >
Date:   Mon Feb 24 07:50:56 2014 -0800

    Started tracking changes to site with git.

If you want to see the changes that were made as well, use the -p option (page option) and the output will be piped into a pager where you can page through all the changes. Hit ‘q’ to quit the pager.

You can browse the commit messages with the –pretty option.


$git log --pretty=oneline
4623ad2cbe4163e2d013c7e53728023e4d7163e6 Added a disallow
065b7362f9ad19d6e2fe69cde9629abf0beabb95 Changed site name and added blank line at end of files
61277e4d12636044e9b873608c325470d98577e0 Started tracking changes to site with git.

Once you have identified the commit you want more info on you can display the info with git show and the first few digits of the hash. Usually five digits is enough to uniquely identify the commit, but you can use all of them if you want.


$ git show --format=raw 4623a
commit 4623ad2cbe4163e2d013c7e53728023e4d7163e6
tree 9c73a1afbfb9ec4930d3d4ac8d906e6ae4683df6
parent 065b7362f9ad19d6e2fe69cde9629abf0beabb95
author User Name <username@WellGolly.com> 1401807300 -0700
committer User Name <username@WellGolly.com> 1401807300 -0700

    Commit message

diff --git a/robots.txt b/robots.txt
index 90098a4..3aa5532 100755
--- a/robots.txt
+++ b/robots.txt
@@ -1,3 +1,5 @@
 # robots.txt for http://www.rememo.info/

 User-agent: *
+Disallow: /order/
+

Often you might be looking for the last time a particular file was changed. –name-only gives the name of the file, the commit message, and the hash.


$ git log --name-only
commit 4623ad2cbe4163e2d013c7e53728023e4d7163e6
Author: Gordon Miller <developer@well.golly>
Date:   Tue Jun 3 07:55:00 2014 -0700

    Added a disallow

robots.txt

commit 065b7362f9ad19d6e2fe69cde9629abf0beabb95
Author: jscarry <jscarry@learningfundamentals.com>
Date:   Mon Feb 24 09:00:03 2014 -0800

    Started tracking changes to site with git.

Reminder/README.txt
Reminder/Reminder.inc
:

Rename a bunch of files

Photoshop mangles file names when you run batch saves on them, so I’ve had to rename a bunch of files after processing. Here’s what I do from the shell prompt to rename a bunch of files in a PictsFolder.

Create a file called rename.sh


#!/bin/bash
cd /Users/gmiller/Desktop/PictsFolder
mv 1.png a.png
mv 2.png b.png
exit

chmod it to be executable. I use chmod 777 rename.sh because I’m lazy. Then run it from the command line.

jscarry$ /Users/gmiller/Files/renamePicts.sh
Be sure to escape special characters like spaces in your file names.

e.g. File\ Name\ With\ Spaces.png

Hybrid Disc Problems with Toast and Director

We’ve been using Toast to burn Hybrid CDs since 1994. When I first purchased the new version I was a bit upset that they took out the ability to burn old-style hybrid CDs. However, they didn’t remove the functionality, they just turned it off. Go into the preferences and enable “Show legacy formats and settings” and it will behave just like it did before. Well, almost. Now it has some really annoying animation, but otherwise it works the same. One other difference was a bit harder to track down and fix.

All of our software current software titles were made with Macromedia Director and with the introduction of OSX Lion they no longer work. The transition to Adobe Director 11.5 has been relatively painless except for some old Flash code in Actionscript 1.0 that hasn’t updated nicely to ActionScript 2.0.

However, when we gave the discs to some people in the office to test they got two errors. When they tried to run program from the disc, an application alert came up telling them “This application requires Adobe Shockwave 11, which can not be found. Click to download it.” If they try to copy it to the hard drive, they get a different error. “The alias “Gamename” cannot be copied to the destination, perhaps because the destination does not support this type of alias.” Our development machines don’t give any errors—even the alias one.

It turns out that the problem is in the way Toast handles (or rather doesn’t handle) aliases in the app bundle.

The app bundle looks like this

Hybrid CD Error

If you follow the aliases you’ll find that
DPLib ==> /Contents/Frameworks/DPLib.framework/Versions/A/DPLib
Resources ==> /Contents/Frameworks/DPLib.framework/Versions/A/Resources

Replace the aliases with the source files, and do the same thing in IMLLib.framework and ProjLib.framework. As near as we can tell the Current alias isn’t necessary and can be deleted from all three locations.

Once you have all your aliases replaces and successfully burned a test CD, make a copy of the Frameworks folder. You can replace the Frameworks folder in new apps with the one that you have working.

The solution was tested on OSX 10.3.9, 10.4.11, 10.5.8, and 10.6.8. We haven’t had access to a Lion machine yet.

Color Depth

We started out making games with Director 4 back when Windows only supported 8 bit palettes and monitors were 640×480. We chose a background color from the Mac Palette that is hex #0066FF. About 5 years ago we updated our movies so that they would fill the whole screen on larger monitors. Most of the backgrounds and menus Flash .swf files. They scale nicely at all resolutions. We had a bunch of backgrounds masks that are solid colors so we just transformed them to 16 bit bitmaps.

We’re updating a bunch of Director movies to D11.5 so that they will run on OSX Lion and our graphic designer noticed that the backgrounds weren’t exactly the right color. It turns out that Director, for its usual inscrutable reasons, didn’t map the Mac Palette color to #0066FF and they ended up being #0063FF instead. Transforming them back to 8 bit and then to 32 bit fixed the problem.