Chapter 27 Flashcards

Controlling Versions with Git

1
Q

Describe version control. 

A

Version control is a method or system that organizes various project files and protects modifications to them. A distributed VCS allows developers to work offline and independently. The Git VCS provides a working directory, staging area (index), and local repository and uses a remote repository provided by a third party. It is popular due to high performance, maintained modification history, file protection, and decentralization.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Explain how to set up your Git environment. 

A

The git package provides the various Git tools used for VCSs. Create a working directory for each project using the mkdir command. The .git/ directory, used by both the staging area and the local repository, is initialized via the git init command. Finally, a third party, such as GitHub, can provide the remote repository to use with the various Git tools.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Detail committing with Git. 

A

As needed, files are moved from the working directory to the staging area (index) via the git add utility. The project’s workflow dictates when the programs are moved to the local directory via the git commit command and then on to the remote repository via the git push utility. If a remote developer needs the latest project files, the git pull command is used. For new team members who need all the project files, including modification history, the git clone command is used.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Summarize Git branches. 

A

A Git branch is a local repository area employed for a particular project section, such as development or project testing. By default, the main branch is called the master branch. New branches are created using the git branch branch‐name command. You can view the various branches available using the git branch utility, which uses an asterisk to denote the current branch. To switch to another project branch, git checkout branch‐name is employed. After work on the branch is completed, its VCS files and project files can be merged with another branch via the git merge branch‐name‐to‐merge command.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Which of the following is true concerning version control? (Choose all that apply.)

Provides a common place to merge and store files
Requires filenames to contain version numbers
May be distributed or nondistributed
Helps to protect files from being overwritten
Can deal with files other than programs
A

A, C, D, E. Options A, C, D, and E all contain true statements concerning version control and are therefore correct answers. Version control does not require filenames to contain version numbers, and thus, option B is an incorrect choice.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Conceptually Git is broken up into distinct areas. Which of the following is one of those areas? (Choose all that apply.)

Blob
Local repository
Remote repository
Index
Working directory
A

B, C, D, E. Conceptually Git is broken up into distinct areas, which are the working directory, the staging area (also called the index), the local repository, and the remote repository. Therefore, options B, C, D, and E are correct answers. A blob is another name for an object stored by Git in the .git/objects/ directory. Thus, option A is an incorrect choice.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Which of the following are steps needed to set up a Git environment for the first time? (Choose all that apply.)

Create a working directory.
Initialize the .git/ directory in the working directory.
Set up the local repository options.
Add files to the staging area when ready.
Establish the remote repository.
A

A, B, C, E. The steps listed in options A, B, C, and E are all involved in setting up a Git environment for the first time. Adding files to the staging area is done after the environment is set up and files have been created in the working directory. Therefore, option D is the only incorrect choice.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Natasha has created her working directory for a new project. What should she do next to set up her Git project environment?

Issue the mkdir command.
Enter the git config ––list command.
Set up her GitHub repository.
Enter the git init command.
Start creating her program files.
A

D. Because Natasha is setting up her Git environment, she should next create and initialize the .git/ directory in her working directory, via the git init command. Therefore, option D is the correct answer. The mkdir command is employed to create the working directory, which is already done, so option A is a wrong answer. The git config –list command shows configuration data, which should be done after the .git/ directory is initialized, so option B is a wrong choice. While Natasha could set up her GitHub repository now, it is not the best next step, so option C is a wrong answer. Starting to create program files is an incorrect choice since Natasha is still setting up her Git environment. Therefore, option E is incorrect.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

When setting his Git configuration options, Bruce employs the ––global option on his commands. What does this mean?

The configuration information is stored on GitHub.
The configuration information is stored in ~/.gitconfig.
The configuration information is stored in the working directory's .git/config file.
The configuration information is stored in the working directory's .git/index file.
The configuration information is stored in the working directory's .git/objects directory.
A

B. Since Bruce employed the –global option when setting his Git configuration options, the information is stored in the global ~/.gitconfig file. Therefore, option B is the correct answer. This Git configuration information is not stored on GitHub, and GitHub may not even be employed as the remote repository in this case, so option A is a wrong answer. The working directory’s .git/config file is the local file, not the global one, so option C is a wrong choice. The .git/index file and .git/objects directory do not store this type of data, so options D and E are incorrect choices.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Bruce has set up his Git environment and finished working on his new GreenMass.sh script. What should he do next?

Add the script to the staging area.
Issue the git init command.
Commit the script to the local repository.
Issue the git log command.
Commit the script to the remote repository.
A

A. The next step Bruce should take is to add his new script to the staging area (index) via the git add GreenMass.sh command. Therefore, option A is the correct answer. The git init command is used to initialize the .git/ directory in the working directory and is part of setting up the Git environment, so option B is a wrong answer. The script cannot yet be committed to the local repository because it has not been added to the staging area. Thus, option C is an incorrect choice. The git log command shows the commit history and is not appropriate at this point, so option D is a wrong answer. The script cannot be committed to the remote repository until it is committed to the local repository. Therefore, option E is an incorrect choice.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

There are 25 files in Natasha’s working directory and she only wants to add 22 of them to the index. She plans on using the git add . command to be efficient. What should she do?

Move the three files out of her working directory.
Add the 22 files individually via the git add command.
Create a new working directory for the three files.
Add the three files' names to a .gitignore file.
Temporarily delete the three files.
A

D. Natasha is being efficient by employing the git add . command, which will add all the files within the working directory to the staging area (index). To stay efficient, she should create a .gitignore file in the working directory and add the names of the three files that she wishes to keep out of the index to that file. This will prevent them from being added. Therefore, option D is the correct answer. While Natasha could move the three files out of her working directory, that is a sloppy and inefficient choice, so option A is a wrong answer. She also could add the 22 files individually to the index, but that too is very inefficient, as is creating a new working directory for the three files. Thus, options B and C are incorrect answers. Temporarily deleting the three files would force Natasha to re-create them after the other files are added to the index. This too is sloppy, and therefore option E is an incorrect choice.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Natasha has completed her open source project, which is set to be released to the public today. She has moved the files to the staging area, committed her work to the local repository, and configured the remote repository’s address. What is her next step?

Go home and relax. She deserves it.
Clone the remote repository to her local system.
Push her project to the remote repository.
Pull her project from the remote repository.
Use the remote add origin URL command.
A

C. Natasha is ready to push her project to the remote repository, so option C is the correct answer. While she may go home and relax later, if the project is released to the public, she must upload it to the remote repository first. Therefore, option A is a wrong answer. Cloning a remote repository is done when someone wants all the project files as well as the VCS history. In this scenario, Natasha already has that data, so option B is a wrong choice. Since the project is complete, there is no need to pull down any files from the remote repository. Therefore, option D is also an incorrect answer. The remote add origin URL command is used to configure the remote repository’s address (URL), which Natasha has already accomplished. Thus, option E is an incorrect choice.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Which of the following commands allows you to switch to a new Git branch called testing?

git branch testing
git ls‐tree ––name‐only ‐r testing
git branch
git commit ‐m "testing"
git checkout testing
A

E. The git checkout testing command will allow you to switch to a new Git branch called testing. Thus, option E is the correct answer. The git branch testing command creates a new branch called testing instead of switching to it. Thus, option A is a wrong answer. The command in option B allows you to view the names of any files managed by the testing branch, so it is an incorrect answer. The git branch command shows you the current branches within this project and designates which one is current via an asterisk, but it does not allow you to switch branches. Thus, option C is an incorrect answer. The command in option D will perform a commit to the local repository and add a comment of testing to the log file. Therefore, option D is also an incorrect choice.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Tony created a new branch of the StoneTracker project called report. He has completed and tested his work. He now needs to merge it with the StoneTracker project’s master branch. After switching branches to the master branch, what command should he employ?

git merge master
git merge report
git rebase master
git rebase report
git checkout master
A

B. The git merge report command will merge the report branch into the master branch as desired, so option B is the correct answer. The git merge master command will attempt to merge the master branch into another branch, but since Tony is already in the master branch, this will not work (and is not desired), so option A is a wrong answer. The rebase arguments will attempt to perform a rebase instead of a merge. Thus, options C and D are incorrect answers. The git checkout master command was already used by Tony to reach the master branch, and thus option E is an incorrect choice.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly