CSCI 2134 Using Git

【CSCI 2134 Using Git】CSCI 2134 Lab 1: Using Git
Winter 2021
Objective
In this lab, you will apply your knowledge of version control, notably Git, to manage a set of files
for a project. You will be given a Git repository of a project and will be asked to perform several
changes to the files in the project.
Aside: The code in question comes from a sequence of assignments that students were assigned
in CSCI 3136, which involved writing an interpreter for a small language. This lab is intended to
be a simulation of these assignments. You will be given all the intermediate source files and will
be adding them to the project as if you were writing it yourself. That is, the following lab represents
the set of steps students would need to do to store and manage their assignments in Git.
Preparation
It is STRONGLY recommended that you complete Task 1 of Assignment 1 prior to this lab.
Ensure that your CSID is active and you can log into your GitLab account at
https://git.cs.dal.ca.
If not, please see instructions in Assignment 1 to accomplish this. All work will be done in the CS
GitLab server. Do not use an external Git service like GitHub.
Ensure that you have read and understood the material on version control and Git from the
course. You might also gain some insights through an online Git tutorial, like the one at
https://try.github.io.
Resources
Support files: https://git.cs.dal.ca/courses...
Procedure
Set-up

  1. Open a command-line window (Terminal on a Mac or gitbash on Windows)
  2. Create the directory where you would like to store a local copy of Lab 1. e.g.,
    mkdir git/csci2134/lab_1
    The above assumes that you have already created a git directory in your home directory
    and a csci2134 directory inside the git directory.
  3. Change directories to where you would like to store a local copy of Assignment 1, e.g.,
    cd git/csci2134/lab_1
  4. Clone the repository for lab 1 supporting files repository, which you will need for the lab.
    Use the following command and Git URL:
    git clone https://git.cs.dal.ca/courses...
    A directory called lab1-support-files will be created. Ensure that it contains the following
    subdirectories, each with files in them:
    v1 splatlex.py
    v2 splatparse.py
    v3 splat.py splateval.py
    v4 splat.py splatred.py
    v5 splat.py splatlambda.py
    v6 splat.py splatselect.py
    v7 splat.py splatuard.py
  5. Clone the repository for your lab 1 using the following command and Git URL
    git clone https://git.cs.dal.ca/courses...
    where ???? is your CSID. A directory with the same name as your CSID will be created,
    containing Lab 1 code.
  6. Change directories into the cloned lab 1 repository, where ???? is your CSID.
    cd ????
    Part 1: Accessing the History of a Project
  7. Checkout (switch to) a branch called incremental:
    git checkout incremental
    You will see a directory called incremental, which will contain a file called splat.py.
  8. Check to ensure you are on the right branch
    git status
    You will should see a message of the form
    On branch incremental
    nothing to commit, working tree clean
    You should use git status regularly to confirm the branch and files you are working on.
  9. Create a temporary text file outside of the local repository (e.g., on your Desktop) to record
    answers to the following questions:
    a. How many versions of splat.py have been committed on this branch? Use the command
    git log to view all commits and the following command to view just all commits of
    the specific file
    git log -- incremental/splat.py
    b. For each of the commits, what was the date and the commit comment?
    c. Which class was added to splat.py before the current version? Use the command:
    git diff HEAD^ -- incremental/splat.py
    Note: HEAD refers to the tip of the branch; HEAD^ refers to the previous commit, and
    HEAD^^ refers to the commit before that, etc.
    d. How many lines of code was the first commit of incremental/splat.py (scanner)?
    Hint: to move to a previous commit you can use the command
    git checkout HEAD^
    Repeating this command will move you to the preceding commit. The command
    git checkout incremental
    returns you to the tip of branch. To count the number of lines, simply load the file into
    an editor.
  10. Return to the main branch
    git checkout main
    Notice that the incremental directory has vanished and that a file called answers.txt
    has appeared in the lab 1 directory. Use git status to confirm that you are on the
    main branch.
  11. Record the answers to the questions in the answers.txt file. Record also your name
    and banner number to make the marker’s life easier.
  12. Prepare to commit the changes you made to answers.txt. This is called staging:
    git add -A
  13. Check to ensure that the file has been staged
    git status
    The modified files should be listed.
  14. Commit the changes
    git commit -m “Added answers to Part 1 of the lab”
    Note: the -m switch allows you to specify a commit comment on the command line. If it is
    not provided, an editor will be invoked for you to add a commit comment.
  15. Push the changes back up to the repository
    git push origin main
    Part 2: Basic Operations
    Whenever we make changes to a code-base, the recommended procedure is to (i) branch the
    code-base, (ii) make the changes in the branch, merge the branch back into the main branch
    once you are satisfied with them. Hence, the motto: “branch often and commit early”. For the
    second part of the lab we will do this a few times to practice our skills. Note: that the first time
    we commit in a repository, we can commit on the main branch.
  16. Create a src subdirectory in the lab 1 directory (same location as answers.txt):
    mkdir src
  17. Copy the files from the lab1-support-file/v1 to src
  18. Add (Stage), check status, commit, and push the changes, like in steps 12 – 15
    The rest of the lab involves simulating the development of the code:
  19. Create a branch from the main branch called development:
    git branch development
  20. Switch to the development branch, similar to steps 7 – 8
  21. Copy the files from the lab1-support-file/v2 to src.
  22. Add and commit the changes, with a suitable commit message
  23. Repeat steps 21 and 22 with the files in v3, v4, v5, v6, and v7 directories. If you were doing
    this over the span of several days, step 23 would also be done for each version, ensuring
    your code is backed up on a remote server.
  24. Push the development branch to the repository
    git push -u origin development
    Having finished (and presumably tested) the code, we now merge it back to the main branch
  25. Switch to the main branch (like in step 10)
  26. Merge the development branch into the main branch
    git merge development
  27. Push the main branch to the repository (like in step 15)
  28. Log in to the git web interface and check that your files were added, committed and pushed
    successfully: https://git.cs.dal.ca/courses...
  29. You’re done!
    Grading
    The lab will be marked out of 4 points:
    Task 2 Points 1 Point 0 Points
    Task
    1
    All questions are answered
    in answers.txt. Answers
    are mostly correct.
    The file answers.txt
    has been modified and
    contains some answers.
    The file answers.txt
    has not been modified,
    Task
    2
    The commit and merge history
    is mostly correct.
    Some of the commits and
    merges have been done.
    No evidence of any commits
    or merges.

    推荐阅读