UNB/ CS/ David Bremner/ teaching/ cs2613/ labs/ Lab 2

Background

Git Tutorial Continued

Making Changes in git

Time
20 minutes
Activity
Individual work, or Pairs
Summary
Get some practice commiting your changes to git.
Notes
If you do work in pairs, make sure you both get some hands on practice.

Having at look at our test post from Lab 1, we can observe the post template adds a bunch of stuff related to social media. Let's suppose that for our cs2613 journal we want a more minimal look.

Start by finding the right files to edit with

$ git grep disqus

git grep is a very useful (and fast!) tool to find occurrences of strings in your git repository. Notice in the output there are some files created by frog; we will clean those up later. Find the template file (under _src) and edit it to remove the undesired social media links. Check the results with

$ raco frog -bp

Use git add to stage your changes:

$ git add file1 file2 file3

You are now ready to commit. You can see what is about to be committed using git diff with the --cached option:

$ git diff --cached

(Without --cached, git diff will show you any changes that you’ve made but not yet added to the index.) You can also get a brief summary of the situation with git status:

$ git status
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#       modified:   file1
#       modified:   file2
#       modified:   file3
#

It’s a good idea to begin the commit message with a single short (less than 50 character) line summarizing the change, followed by a blank line and then a more thorough description. The text up to the first blank line in a commit message is treated as the commit title, and that title is used throughout Git.

If you need to make any further adjustments, do so now, and then add any newly modified content to the index. Finally, commit your changes with:

$ git commit

This will again prompt you for a message describing the change, and then record a new version of the project.

Alternatively, instead of running git add beforehand, you can use

$ git commit -a

which will automatically notice any modified (but not new) files, add them to the index, and commit, all in one step. Keep in mind that you will be marked on the logical structure of your git commits, so you are better off using git add to explicitely choose what changes to commit.

Cleaning up generated files

Time
20 minutes
Activity
Individual work, or Pairs
Summary
Get some practice commiting your changes to git.
Notes
If you do work in pairs, make sure you both get some hands on practice.

A common phenomenon in software development is the existence of generated files. These files are created by some tool, typically based on some source files. In general it is a bad idea to track generated files in version control because they introduce spurious changes into history. We'll look at this more later, but for now let's try to clean up. We can find out what files are generated .e.g. by consulting the frog docs. Let's first try a shortcut. Run

$ cd ~/fcshome/cs2613/frog
$ raco frog --clean

To find out what changed, run

$ git diff --stat

All going well, you will see a bunch of deletions. We can tell git to make those deletions permanent in several ways. It turns out that there is a handy option to git add that tells git to stage all of the changes in the working tree. Try to figure out which option it is.

When you are satisfied with the changes, run git commit.

It will turn out that this is not all of the generated files; we can use git rm to clean up further as we find more.

Make sure you run

$ raco frog -bp

To make sure the the blog still works after your deletions.

Viewing project history

Time
10 minutes
Activity
Pairs, peer feedback
Summary
Get some practice commiting your changes to git.
Notes
If you do work in pairs, make sure you both get some hands on practice.
  1. You need to work in pairs for this part.

  2. At any point you can view the history of your changes using

     $ git log
    

    Use this command to verify that all the changes you expected to be pushed to the server really were.

    If you also want to see complete diffs at each step, use

     $ git log -p
    

    Often the overview of the changes is useful to get a feel for each step

     $ git log --stat --summary
    
  3. Temporarily trade computers with your partner. Use git log to examine the history of their repo. Consider their commit messages, and the construction of their commits (i.e. what changes are commited together). Discuss how each of your might improve your history.


Racket Tutorial

Hello Racket World

Time
15 Minutes
Activity
Small groups, discussion, puzzle solving

Command Line

DrRacket: A Racket Specific IDE

Squaring the Circle.

Time
20 minutes
Activity
Individual work, or pairs, following a detailed tutorial

Functions, Scope, and Lists

Time
20 minutes
Activity
Individual work, following a detailed tutorial

On your own

In this part of the lab I will give some activities that you should work through on your own after the scheduled lab time. Of course if you finish the rest of the lab early, you can start this part. We will set aside some time for discussion at the beginning of L03.

Working with multiple git repos

Time
30 minutes
Activity
Individual work, after scheduled lab time.

Cloning

  1. Open a terminal on the FCS Linux session (i.e. not in the fcs-cs2613-dev VM). Make a directory lab1-scratch somewhere outside the cs2613 git repository you created earlier.

  2. Now move to the lab1-scratch directory, and make a clone of the central repo.

     $ git clone https://<username>@vcs.cs.unb.ca/git/cs2613-<username> cs2613-clone
    

    This creates a new directory "cs2613-clone" containing a clone of your repository. Notice that in general this is a good way of checking that your work is properly submitted. The TA and Prof will do exactly this cloning step in order to mark your work. The clone is on an equal footing with the original project, possessing its own copy of the original project’s history.

Sharing changes with a central repo

  1. Switch to (or open) a terminal in the fcs-cs2613-dev VM.

  2. Navigate to the ~/fcshome/lab1-scratch/cs2613-clone/frog directory.

  3. create a new blog entry, and commit it.

  4. Push your changes back to the central repository.

     $ git push origin master
    
  5. Change directory to your original directory ~/fcshome/cs2613. Bring in the changes you made

     $ git pull origin
    

This merges the changes from the central copy of "master" branch into the current. branch. If you made other changes in the meantime, then you may need to manually fix any conflicts.

The "pull" command thus performs two operations: it fetches changes from a remote branch, then merges them into the current branch.

Questions

Here are some questions we will be discussing at the beginning of L03.

Git next steps

Congratulations, you now know enough git to finish this course.

There is lots more to learn, particularly about branching and collaboration. If you want to get a big(ger) picture view, a good place to start is Git Concepts Simplified.

Racket development tools

Time
30 minutes
Activity
Individual work, after scheduled lab time.

Byte compilation

Racket and IDEs

Questions

Here are some questions we will be discussing at the beginning of L03.