【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
- Open a command-line window (Terminal on a Mac or gitbash on Windows)
- 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. - Change directories to where you would like to store a local copy of Assignment 1, e.g.,
cd git/csci2134/lab_1 - 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 - 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. - Change directories into the cloned lab 1 repository, where ???? is your CSID.
cd ????
Part 1: Accessing the History of a Project - 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. - 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. - 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. - 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. - 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. - Prepare to commit the changes you made to answers.txt. This is called staging:
git add -A - Check to ensure that the file has been staged
git status
The modified files should be listed. - 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. - 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. - Create a src subdirectory in the lab 1 directory (same location as answers.txt):
mkdir src - Copy the files from the lab1-support-file/v1 to src
- 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: - Create a branch from the main branch called development:
git branch development - Switch to the development branch, similar to steps 7 – 8
- Copy the files from the lab1-support-file/v2 to src.
- Add and commit the changes, with a suitable commit message
- 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. - 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 - Switch to the main branch (like in step 10)
- Merge the development branch into the main branch
git merge development - Push the main branch to the repository (like in step 15)
- Log in to the git web interface and check that your files were added, committed and pushed
successfully: https://git.cs.dal.ca/courses... - 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.
推荐阅读
- Git合并策略选项及示例
- git|Ubuntu 20上安装 gitlab git 服务器
- docker|使用 GB28181.Solution + ZLMediaKit + MediaServerUI 进行摄像头推流和播放
- Spring|Docker安装gitlab及修改gitlab密码
- AI 智能卡证分类(行政人力减负新神器,「金三银四」轻松度过)
- PLG SaaS 时代,《2022年 如何做好内容营销》白皮书
- Gitlab-ci 替代 webhook 触发Jenkins job
- AliOS|开源社区第一步 使用 Pull Request 向 git 仓库贡献代码
- 版本管理工具|Git使用(Git安装、建立Git仓库、克隆Git仓库、提交代码至Git仓库)