A few notes, all commands in this tutorial will assume you are working in a linux shell. The same commands should work for OSX but have not been tested. This primer is not intended to give you a full breadth of coverage of the git toolset but show you the basics of making a repository, recording changes, reviewing differences over time, and pushing and pulling from a remote repository. We won't be working with any of the graphical tools for the time being as they are all very different, but the underlying tech to all of them is the same commands we will be doing on the command line.
To get started we'll need a place to work, so lets create that and populate it with some files. I'll be using the files from https://gist.github.com/Wildcarde/9079ead23d5651d871e0 for this demo but feel free to use other files if you would like to.
mkdir gitclass
cd gitclass
wget https://gist.github.com/Wildcarde/9079ead23d5651d871e0/raw/e68a6db01c3e9786d1a49a1b14064dc30f1e18ac/drawfigure.m
wget https://gist.github.com/Wildcarde/9079ead23d5651d871e0/raw/e68a6db01c3e9786d1a49a1b14064dc30f1e18ac/testdraw.sh
We have a folder with some content now but it's not under version control, first lets enable version control of the gitclass folder with the following:
git init
git status
git log
This will create a .git folder adding the structures needed for git to work inside and show you the current status of the working directory vs. that git repository. Now we will add those files to the commit log and commit them to git with the following:
git add *
git status
git commit -m "adding the initial commit to the repository"
git log (q to quit)
These files are now under version control in the source control system, so lets add a few changes to the files to see what happens. First I'm going to make some modifications to drawfigure.m changing the output filename and scaling variable in the file. These changes can then be reviewed, added to staging and committed.
git diff
git commit -a -m "changing scaling factor and correcting output filename"
git log (q to quit)
To add a few more commits I'm going to update the testdraw.sh script with some comments, then to use xvfb-run instead of manually creating it's own xvfb instance since it's safer overall.
#--- make comment updates
git diff
git commit -a -m "adding some notes to testdraw.sh"
git log
#--- make xvfb-run changes
git diff
git commit -a -m "correcting some errors based on knowing how xvfb-run works now."
git log
Now that there are a few lets review all the changes, to do this we will first need to retrieve the hash for the first commit and copy it. After that we can issue a git diff against a specific version like so:
git diff -r e0943ae15b979fa930522730d7eb552da220f6a6 (replace this has with your local git log hash number)
If you want to see the revision history for only a single file add it to the end like so:
git diff -r e0943ae15b979fa930522730d7eb552da220f6a6 testdraw.sh