w1d6-w1d7 (Git) Flashcards

1
Q

How can all files of a certain type be added to a commit?

A

Use a wildcard:

git add ‘*.txt’

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

What is the syntax to add a named repo?

A

git remote add repo_name repo_address

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

What does the -u flag do in the following command:

git push -u origin master

A

Tells git to remember the parameters for the push command, so ‘git push’ will suffice in the future.

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

What is the syntax to retrieve changes to a repo?

A

git pull reponame branchname

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

What does the following command do:

git diff HEAD

A

Assesses the difference between local files and the latest commit.

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

How can we assess the difference between staged files and the last commit?

A

git diff –staged

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

What is the command to unstage a file?

A

git reset filepath/filename

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

How can we revert a file to its state at the last commit?

A

git reset – filename

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

Explain the following command:

git rm ‘*.txt’

A

Removes all .txt files in the repo from the desk and the staging area.

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

What is the point of the -a flag in the git commit command?

A

Auto removes files that were removed from the disk but not the staging area when the next commit occurs.

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

What is a VCS?

A

A version control system; keeps track of different versions of files/projects.

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

What is a CVCS?

A

A centralized version control system; keeps track of files on a server which multiple users can access.

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

What is a DVCS?

A

A distributed version control system; versions are stored on a databases, and a user copies the entire repo everytime they access the files; prevents a single point of failure by ensuring that versions are distributed to multiple locations.

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

What makes Git so fast?

A

It stores all commits as a series of snapshots on the server, distributed to all local machines, so local machines have access the the entire repo and do not need to always go back up to the server.

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

What is the point of the checksum used to identify commits?

A

The checksum is based on the contents and directory structure at that time, so it is impossible to alter a file without Git knowing it.

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

What are the three sections of a Git project, and what are the differences between them?

A

The .git repository, where all commits are stored, the Staging Area, where files are added to when they are planned to be committed, and the Working Directory, which consists of files on the local machine.

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

What are the three states of a file in Git?

A

It can be committed, meaning a snapshot of the file in its current state has been taken, it can be modified, which means it is different than its last snapshot and is not being tracked, and staged, meaning it is different from its last snapshot and has been added to be committed.

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

What are the three ways for getting help for a git command?

A

$ git help
$ git –help
$ man git-

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

What is the distinction between snapshots and differences? Which does Git use?

A

Differences store a list of files and the changes made to them over time; snapshots store the files in their entirety each time they are committed (a file with no changes can be given a pointer back to the last changed version of the file). Git uses snapshots.

20
Q

What does the ‘git clone’ command do, and how is it used?

A

It allows you to copy an existing Git repository in its entirety. The syntax is:

$git clone repo_address optional_directory_name

21
Q

What is the difference between a tracked and an untracked file?

A

A tracked file was included in the last snapshot; it can be unmodified, modified, or staged.

An untracked file was not included in the last snapshot and is not staged.

22
Q

What happens when you pass ‘$git status’ a directory as an argument?

A

All files in the directory will be tracked recursively.

23
Q

T/F: If you modify a file after running ‘$git add’ on the file, you will have to add it again.

A

T

24
Q

What is the flag added to the status command to produce a more succinct output?

A

$git status -s

25
Q

What is the .gitignore file, and how can it be used to ignore generated files?

A

It tells Git to completely ignore files that are either listed or match a wildcard. To ignore generated files, add the following to .gitignore:

*~

This tells Git to ignore files that end with a ~. Similarly, to tell Git to ignore files with a .o or .a extension:

*.[oa]

26
Q

What is some of the syntax for the .gitignore file?

A
# no .a files
*.a
# but do track lib.a, even though you're ignoring .a files above
!lib.a
# only ignore the root TODO file, not subdir/TODO
/TODO
# ignore all files in the build/ directory
build/
# ignore doc/notes.txt, but not doc/server/arch.txt
doc/*.txt
# ignore all .txt files in the doc/ directory and its subdirectories
doc/**/*.txt
27
Q

What does ‘git diff’ show?

A

Unstaged changes

28
Q

How can we see changes between staged files and the last commit?

A

$git diff –staged

29
Q

How can a file be removed from a file from the staging area but let it remain on the disk?

A

$git rm –cached filename

30
Q

How can the ‘git mv’ command be used?

A

To rename a file:

$git mv from_file to_file

31
Q

Explain the following command:

$git log -p -2

A

Shows the differences between commits for the last two commits.

32
Q

Explain the following command:

$git log –since=2.weeks

A

Show all commits from the past 2 weeks.

33
Q

What does the –amend option do in ‘git commit’

A

Runs a commit that replaces the previous commit altogether.

34
Q

How can you revert a specific file to its state at the time of the the last commit?

A

$git checkout – filename

35
Q

How do you unstage a file?

A

$git reset HEAD filename

36
Q

How can you list all of your remote repositories with their address and their alias?

A

$git remote -v

37
Q

How can you retrieve the contents of a remote and place them as branches in your repo?

A

$git fetch repo_url_or_alias

38
Q

What is the difference between fetch and pull?

A

Fetch pulls the repo branches but does not merge them; pull retrieves a the HEAD (current branch of the remote) branch and merges it.

39
Q

How can you inspect a remote?

A

$git remote show repo_name

40
Q

How can you rename the alias of a remote?

A

$git remote rename old_name new_name

41
Q

How can you alias a Git command?

A

$git config –global alias.alias_name old_name

42
Q

How can you set the authorship of commits on a local machine?

A

git config user.name “username”

git config user.email “email”

43
Q

How can you setup a remote that uses https when pushing?

A

https://github.com/your_username_here/repo_name.git

44
Q

How do we stage all files including new ones?

A

$git add -A

45
Q

How can we add an alias for a command to Bash?

A

Change ~/.bash_profile to include the line:

alias alias_name=’full command’