0% found this document useful (0 votes)
57 views28 pages

Version CTRL Git

Git is a distributed version control system (DVCS). Three software engineering problems that Git helps solve are: 1. Recovering older versions of code - With Git, the entire history of a codebase is stored locally in each developer's repository. This allows developers to easily recover older versions of files or entire projects if needed. 2. Parallel development - Multiple developers can work on different branches of a project simultaneously without interfering with each other. Changes can be merged together later when ready. This enables teams to work more efficiently. 3. Collaboration - Git allows developers to collaborate easily by sharing code through a remote repository (e.g. GitHub). Developers can pull changes from the remote to stay up-to-date or push
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
57 views28 pages

Version CTRL Git

Git is a distributed version control system (DVCS). Three software engineering problems that Git helps solve are: 1. Recovering older versions of code - With Git, the entire history of a codebase is stored locally in each developer's repository. This allows developers to easily recover older versions of files or entire projects if needed. 2. Parallel development - Multiple developers can work on different branches of a project simultaneously without interfering with each other. Changes can be merged together later when ready. This enables teams to work more efficiently. 3. Collaboration - Git allows developers to collaborate easily by sharing code through a remote repository (e.g. GitHub). Developers can pull changes from the remote to stay up-to-date or push
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 28

Multiple-Choice Questions:

1. Which of these terms best describes Git?

a. Integrated Development Environment

b. Distributed Version Control System

c. Issue Tracking System

d. Web-Based Repository Hosting Service

e. None of the above

2. Which of the following problems does Git help solve?

a. Recovering older versions of a software project

b. Developing multiple versions of a software project in parallel

c. Merging changes to a software project made by collaborating developers working in parallel

d. All of the above

e. None of the above

3. Which of these terms best describes GitHub?

a. Integrated Development Environment

b. Distributed Version Control System

c. Issue Tracking System

d. Web-Based Repository Hosting Service

e. None of the above


4. Which of these Git client commands creates a copy of the repository and a working directory in the
client’s workspace. (Choose one.)

a. update

b. checkout

c. clone

d. import

e. None of the above

5. True or False? In Git, if you want to make your local repository reflect changes that have been made
in a remote (tracked) repository, you should run the pull command.

a. True

b. False

6. In Git, which error would you get if you try to push master-branch changes to a remote repository,
and someone else pushed changes to that same branch while you were making your changes? (Choose
one.)

a. Rejected

b. 404

c. 500

d. Access denied

e. 400 Bad request

7. If you want to make radical changes to your team’s project and don’t want to impact the rest of the
team, you should implement your changes in …

a. … a tag.

b. … the trunk.

c. … the root.

d. … a branch.

e. None of the above


8. Imagine that you just joined a development team that uses Git for version control and collaboration.
To start contributing to the project, what Git operation would you most likely invoke first?

a. checkout

b. clone

c. export

d. revert

e. update

9. Now, imagine that you have a local repository, but other team members have pushed changes into the
remote repository. What Git operation would you use to download those changes into your working
copy?

a. checkout

b. commit

c. export

d. pull

e. update

10. The Git clone command does which of the following?

a. Creates a working directory

b. Makes a local copy of the repository

c. Commits a new branch

d. a and b

e. a, b, and c
11. Which Git command changes where the HEAD pointer points and modifies the contents of the work-
ing directory?

a. checkout

b. merge

c. mv

d. pull

e. None of the above

12. Which one of the following is not part of the data structure of a Git repository?

a. Body element

b. Branch pointer

c. Commit object

d. HEAD pointer

e. None of the above (i.e., they are all parts)


Solutions:

1. b

2. d

3. d

4. c

5. a

6. a

7. d

8. b

9. d

10. d

11. a

12. a
Problem:

Consider the following scenario involving Git. Alice and Bob are both working on a shared project My-
Proj that is stored in a remote Git repository. Bob does a clone on the remote repository. What two things
does Git create when Bob issues the clone command?

Next, Bob edits the MyProj file foo.rb. Then, he does a commit and a push. What does Git do when Bob
issues these commands?

Next, Alice does a clone on MyProj. Then, Alice and Bob both edit foo.rb in parallel. foo.rb has over
100 lines of code. Alice edits a couple lines at the top of the file, and Bob edits a couple lines at the bot-
tom of the file. Then, Bob does a commit and a push. Finally, Alice does a commit and a push. What
does Git do when Alice issues the push command?

What Git commands should Alice issue next and what would the result of the command be?
Solution:

Consider the following scenario involving Git. Alice and Bob are both working on a shared project My-
Proj that is stored in a remote Git repository. Bob does a clone on the remote repository. What two things
does Git create when Bob issues the clone command?

When Bob issues the checkout command, Git creates a local copy of the MyProj repository and a
working directory that contains the latest snapshot of the project files.

Next, Bob edits the MyProj file foo.rb. Then, he does an add, a commit and a push. What does Git do
when Bob issues these commands?

The add commands “stages” the changes. The commit command updates Bob’s local repository to
reflect the changes. The push command updates the remote repository to reflect the changes in Bob’s
local repository.

Next, Alice does a clone on MyProj. Then, Alice and Bob both edit foo.rb in parallel. foo.rb has over
100 lines of code. Alice edits a couple lines at the top of the file, and Bob edits a couple lines at the bot-
tom of the file. Then, Bob does an add/commit/push. Finally, Alice does a add/commit/push. What
does Git do when Alice issues the push command?

When Alice issues the push command, Git rejects her push because the remote branch has changed
since the last time she pulled from it.

What Git commands should Alice issue next and what would the result of the command be?

Alice should do a pull on the remote repository. That will update her current branch in her local repos-
itory as well as her working directory. The update will both download the changes in the remote repos-
itory and merge them into her current branch. To then upload the merged changes, she would need to
do an add/commit/push.
Problems:
Draw the state of the pictured repository after a Git commit operation (make up a hash).

Before: After:

HEAD%

master%

98ca9% 34ac2%

myfix%

Draw the state of the pictured repository after running the following commands.
$ git checkout master
$ git merge myfix

Before: After:

master%

98ca9% 34ac2%

myfix%

HEAD%
Solutions:
Draw the state of the pictured repository after a Git commit operation (make up a hash).

Before: After:

HEAD%

master%

98ca9% 34ac2%

myfix%

Draw the state of the pictured repository after running the following commands.
$ git checkout master
$ git merge myfix

Before: After:

master%

98ca9% 34ac2%

myfix%

HEAD%
Problems:

1. Imagine a Git repository (“repo”) with one commit and one branch (master). A user makes a new
commit to the repo. Draw a box-and-line diagram of the repo like the diagrams shown in class. In-
clude all commit nodes (with made-up hashes), all HEAD nodes, and all branch nodes.

2. Continuing the previous scenario, the user creates and checks out a new branch “my-branch” and then
makes a new commit. Update the previous diagram to reflect these actions.
Solutions:

1.

2.
Multiple-Choice Questions:

Consider these four versions of a Rails model file, cat.rb:

Version A Version B

Version C Version D

Now, imagine the following scenario. Alice and Bob are using GitHub to collaborate on a Rails project.
They both are working in parallel on Version A of cat.rb. Each modifies the file cat.rb as follows: Alice
changes it to be Version B, whereas Bob changes it to be Version C (note the difference in length maxi-
mum).

Bob commits his changes first, and pushes them to the GitHub repo. Then, Alice commits her changes.

1. Which one of the following would happen if Alice next did a Git push?

a. Her commit would be added to the GitHub repo, making the current version in GitHub be
Version B

b. Her commit would be merged with Bob’s in the GitHub repo, making the current version in
GitHub be Version D

c. Her push would be rejected, leaving the current version in GitHub as Version C

d. Her push would be rejected, leaving GitHub unchanged, and Bob’s code would be download-
ed and merged into her working directory, making her working copy Version D

e. None of the above

2. Which one of the following would happen if Alice instead did a Git pull?

a. Her pull would be rejected, leaving her working directory with Version B of cat.rb

b. Her working directory would be updated to have Version C of cat.rb

c. Her working directory would be updated to have Version D of cat.rb

d. The GitHub repo would be updated to have Version B of cat.rb

e. None of the above


Consider this Git repo.

3. Why does the C5 commit node point at both C3 and C4?

a. Because C5 was created by merging data from C3 and C4

b. Because C3 and C4 were each created by modifying data from C5

c. This example is invalid: The node to which “experiment” directly points (C3) should not be
reachable from the node to which “master” directly points (C5)

d. This example is invalid: C5 should never point at both C3 and C4

e. None of the above


Solutions:

1. c

2. c

3. a
Problem:

What type of system is Git? Describe three software engineering problems Git helps you solve.
Solution:
Problems:

Consider the following list of Git commands:


a) git init f) git branch
b) git push g) git clone
c) git add h) git checkout
d) git merge i) git status
e) git commit j) git pull

Alice is working on a collaborative software project with a team of seven other developers. The project is
an airline-booking web app called FlyMe. The code for the project is housed in a GitHub repo. All work
for the project is being done on the “master” branch (no other branches). Alice has been helping on the
project for a while, and has a local copy of the repo and a working directory on her computer.

1. Alice has just edited the web-app code on the master branch to add a feature that enables users to re-
quest window or aisle seats when they book flights. She wants to save these changes in her local repo.
Which command(s) from the above list should she run next?

2. Having saved the changes in her local repo, Alice now wants to share them with the rest of the team
by uploading them to the GitHub repo. Which command(s) from the above list should she run next?

When she runs the command(s), she gets this message (with words that give away the answers hidden):

To https://github.com/.../flyme.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'https://github.com/.../flyme.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

3. Alice wants to resolve this issue, so she can upload her changes. Which (one) command from the
above list should she run next?
Solutions:

1. c, e

2. b

3. j
Problems:

Draw the state of the pictured repository after a Git commit operation (make up a hash).

Before: After:

master%

98ca9% 34ac2%

myfix%

HEAD%

Draw the state of the pictured repository after running the following command.

git merge myfix

Before: After:

HEAD%

master%

98ca9% 34ac2%

myfix%
Solutions:

Draw the state of the pictured repository after a Git commit operation (make up a hash).

Draw the state of the pictured repository after running the following command.

git merge myfix


Problems:

Consider the following list of Git commands:


a) git init f) git branch
b) git push g) git clone
c) git add h) git checkout
d) git merge i) git status
e) git commit j) git pull

Giada has just joined a team of developers collaboratively working on a restaurant management web app
called DineOh. The code for the project is housed in a GitHub repo. All work for the project is being done
on the “master” branch (no other branches).

1. Giada wants to get a local copy of the code and repo, so she can begin contributing to the project.
Which command(s) from the above list should she run?

2. Giada does some work on the project, but then, she is suddenly called upon to fix a critical bug in an-
other project. She is distracted by this debugging task for a couple days. When she finally returns to
the DineOh project, she cannot remember if she saved her edits to the local repo. Which command(s)
from the above list should she run to determine whether or not she saved her edits?

3. The command tells her that she had only edited the files, but not run any other Git commands since
doing so. Which command(s) from the above list should she run to save her edits to the local repo?

4. Having saved to her local repo, she would now like to share her work with the rest of the team (via
GitHub). Which command(s) from the above list should she run?

When she runs the command(s), she gets this message (with words that give away the answers hidden):

To https://github.com/.../dineoh.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'https://github.com/.../dineoh.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

5. Giada wants to resolve this issue, so she can upload her changes. Which (one) command from the
above list should she run next?
Solutions:

1. g

2. i

3. c, e

4. b

5. j
Problems:

1. Draw the state of the pictured repository after a Git commit operation (make up a hash).

Before:
98ca9 34ac2

master

HEAD

After:

2. Draw the state of the local repository after a Git pull operation.

Remote Repo: Local Repo Before:

98ca9 34ac2 29ab6 98ca9 34ac2

master master

HEAD

Local Repo After:


Solutions:

1.

2.
Problems:

Consider the following list of Git commands:


a) git init f) git branch
b) git push g) git clone
c) git add h) git checkout
d) git merge i) git status
e) git commit j) git pull

Bonita has just joined a team of developers collaboratively working on a real estate sales web app called
ProperProperty. The code for the project is housed in a GitHub repo. All work for the project is being
done on the “master” branch (no other branches).

1. Bonita wants to get a local copy of the code and repo, so she can begin contributing to the project.
Which command(s) from the above list should she run?

2. She makes some changes to the code. Which command(s) from the above list should she run to save
her edits to the local repo?

3. Having saved to her local repo, she would now like to share her work with the rest of the team (via
GitHub). Which command(s) from the above list should she run?

When she runs the command(s), she gets this message (with words that give away the answers hidden):

To https://github.com/.../dineoh.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'https://github.com/.../dineoh.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

4. Bonita wants to resolve this issue, so she can upload her changes. Which (one) command from the
above list should she run next?

5. The command completes with no conflicts. What command(s) should Bonita run to at last share her
work with the rest of the team?
Solutions:

1. g

2. c, e

3. b

4. j

5. b (would also accept c, e, b)


Problems:

1. Draw the state of the pictured repository after a Git commit operation (call your hash cdcdcd).

Before:
ababab bcbcbc

master

After:

2. Draw the state of the local repository after a Git pull operation.

Remote Repo: Local Repo Before:

ababab bcbcbc ababab bcbcbc 010101

master master

Local Repo After:


Solutions:

1.

2.

You might also like