Module 1 Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

What is the goal of a version control system (VCS)?

A

To allow tracking of changes made to project files

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

I’ve prepared patch file (fixscript.patch) with changes required to fix a colleague’s script. How does he applies my change to his file?

A

patch original_file.py < fix_script.patch

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

I’m helping a colleague with a bug in a script called file1.py. I made a copy called file1_modified.py to fix the bug. What command do I need to run after solving the bug to send the patch to my colleague?

A

diff file1.py file1_modified.py > file1_fix.patch

Compares file_1modified against file1 and saves changes to file1_fix

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

What I need to provide to the patch command?

A
  1. Original File
  2. Patch file (.diff)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What does the patch command do?

A

It applies the changes contained in a diff file to another file.

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

What is the purpose of the diff command?

A

To show the differences between two files

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

How can using the -u flag with the diff command provide more context for the changes being compared?

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

What are the git directory and the working tree?

A

The git directory contains all the changes and their history and the working tree contains the current versions of the files.

Git Directory: hidden database that stores all the information about your project’s history, changes, and different versions in this directory.

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

What is the difference between tracked and untracked files?

A

Tracked files are part of the snapshots (commits) while untracked filed are not included in the commits.

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

What is the next step after modifying a file tracked by Git?

A

We need to stage the file, so that the changes will be included in the next commit.

This is done via the git add <file_name> command.

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

Describe the situation below

A

There was a change to a file called rearrange1.py in the working tree, but the file has not been added to the stagging area, meaning it will not be include in the next commit.

If we want to include it in the next commit, then we need to use git add

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

Describe the situation below

A

There was a change to a file called rearrange1.py in the working tree and the file was added to the stagging area, meaning it will be include in the next commit.

To commit it, we need to use git commit - m and include a commit message.

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

Explain how the diff command is used in practice and how does it show the difference between files?

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

What are the three main sections of a Git project and what does each section contain?

A
  1. Git Directory (Repository): This is where Git stores all the history of your project, including all commits, branches, and tags. Think of it as a hidden database for your project’s versions.
  2. Working Tree: This is the area where you directly work on your files. It contains the current version of your project that you see and edit.
  3. Staging Area (Index): This is a middle ground between your working tree and the Git directory. It’s where you prepare changes for the next commit. You can add or remove changes from the staging area before committing them to the Git directory. Index is a file.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What the possible states of a tracked file

A

A tracked file can be:
1. modified (changes made but not committed)
2. staged (changes marked for commit)
3. committed (changes stored in a snapshot).

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

What are the main steps involved in using the diff and patch commands to fix bugs in a script?

A

1) Identify and Fix: First, you’d need to figure out what’s wrong in your script and fix those bugs in your code editor. You’ll want to keep your original, buggy script and a separate copy with your fixes.

2) Create a Diff: The diff command comes in to compare your original script with your fixed version. It creates a “diff file” that highlights the changes. Think of it like a set of instructions on how to get from the buggy version to the fixed one.

diff original_script.py fixed_script.py > changes.diff

3) Apply the Patch: Now, you can share this changes.diff file with someone else, or even apply it to a different copy of the script yourself. The patch command takes this diff file and applies the changes to the specified file.

patch original_script.py < change

17
Q

How can using the -u flag with the diff command provide more context for the changes being compared?

A

Using the -u flag with the diff command generates what’s called a “unified diff”. Here’s how it provides more context:

Combined Lines: Instead of showing separate blocks for removed and added lines, the unified format presents them together, with a - for removed lines and a + for added lines. This side-by-side view makes it immediately clear how the lines relate to each other.

Surrounding Context: The unified diff includes a few lines of unchanged code above and below each change. This surrounding context helps you understand the changes within the flow of the code, making it easier to see the purpose and impact of the modifications.

18
Q

How does the patch command work to apply changes from a diff file to the original file?

A

Reading and Understanding: First, patch reads the diff file line by line. It interprets the context lines (those with +, -, and @@ symbols) to understand the changes made between the original and modified files.

Finding the Context: Next, patch searches for the same context lines in the file you want to patch. This is crucial because it allows patch to locate the exact lines where changes need to be applied.

Applying the Changes: Once the context is found, patch follows the instructions in the diff file to add, remove, or modify lines in the target file. It uses the + lines to insert new content and - lines to delete existing content.

Handling Conflicts: Sometimes, the target file might have been modified since the diff was created. In such cases, patch tries its best to resolve conflicts. If it can find a reasonable way to apply the changes despite the modifications, it will do so. Otherwise, it will mark the section as a conflict, requiring manual intervention.

19
Q

How can I initialize a git repository?

A
git init

Empty repository is initialized in current directory

20
Q

What happens when I run git init

A

Executing git init creates a .git subdirectory in the current working directory, which contains all of the necessary Git metadata for the new repository.

This metadata includes subdirectories for objects, refs, and template files. A HEAD file is also created which points to the currently checked out commit

21
Q

Imagine I am editing a file that has been previously committed. How can I quickly check the different versions in repository and in working tree?

A

Use git diff <file_name>

New additions are denoted by green-colored text and a + sign at the start of the line. Any replacements/removal are denoted by text in red-colored text and a - sign at the start of the line.

22
Q

How can I see the history of all commits?

A

git log

23
Q

What is the purpose of the git config command?

A

To configure global or repository-specific settings

24
Q

What is the output from git log -p?

A

Vai mostrar todas as mudanças para cada um dos committ. Se houver muitos committs, serão geradas várias páginas de resultados.

-p vem de patch, que é basicamente uma modificação feita a um programa

25
Q

What is the output from git log --stat?

A

Generates list of committs now with detailed information like the number of changes, type of changes, how many files were changed, etc.

26
Q

Why should I use git add -p?

A

The -p flag tells Git to show me the changes that could be staged should I wish to continue, so it only adds the change if I say so.

27
Q

What is the difference between git diff and git diff --staged?

A

git diff shows only the changes that were not staged. If I want to check changes made to stagged files, I need to use git diff --stagedd instead.

all_checks.py was just stagged

28
Q

How is the output from git show <commitd_ID>?

A

It will show what were the changes from a specific commit.

git show <commit_ID></commit_ID>

29
Q

What is purpose of using git commit -a?

A

It is a way of committing files directly, without having to manually add them to the staging area.

It should be used only when I am certain about the changes to be committed. As I am not manually adding changes to the stagging area, there is less room for errors when committing.

30
Q

Why is it important to know whether files are tracked or not before using git commit -a?

A

git commit -a only works for tracked files. For untracked files, I need to add the to the stagging area manually.