git Flashcards

1
Q

What is a git repository?

A

A git workspace with its own history. It’s like a clade. What you do to one repo does not affect the others.

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

Command to get info on the repo we’re currently in.

A

git status

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

Command to initialize a new empty repo in the current directory.

A

git init. Use mkdir and cd into it, then use git init inside that directory.

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

What is a commit?

A

Basically a snapshot of code in a repo.

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

Difference between saving a file and committing a file.

A

You save a file(s) first, then group them together into a commit.

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

How does a commit work?

A

You group some or all altered files together and commit them. So if you alter 10 files, you can choose a specific group of 3, for example, to commit.

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

Difference between working directory & repository.

A

Working directory - the dir where the files you’ve created reside.
Repo - the .git folder that’s created in the dir with your files when you use the git init command.

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

What is the staging area?

A

This is what we add our changes to before making a commit.

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

Command to add files to the staging area.

A

git add

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

Command to create and add two files to the staging area.

A

touch file1.txt
touch file2.txt
git add file1 file2

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

Command to add all changes in the current dir to the staging area.

A

git add .

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

What is a git message?

A

A message you write when you commit files which explains what has been changed in those files.

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

Command to write commit message with a commit.

A

got commit -m “message”

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

What info does git status give you?

A

If there are any modified files that haven’t been added or committed.

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

Command that gives you a log of the commits for a given repo.

A

git log

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

What info does git log give you?

A

It gives you a log of the commits for a given repo, who made the commits and at what time they were made, and the message associated with each commit. Also a list of all branches & where HEAD is currently pointing.

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

What does it mean to keep commits atomic?

A

When you make a commit, try to focus on one thing. If you alter a particular GUI element and also alter some other thing like button functionality, make separate commits with messages for each of these changes, don’t commit both simultaneously.

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

What command lets you amend a commit?

A

git commit –amend
(only works on previous commit)

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

When should you use git commit –amend?

A

If you do a commit but forget to add one of the files you wanted to commit to the stage beforehand.

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

How does git commit –amend work?

A

It opens up the previous commit message and allows you to edit it, so you could basically re-do the previous commit command with the file you forgot.

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

Command to use if there are files you don’t want to make public or be tracked by git.

A

git ignore

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

How do you make git ignore a list of files?

A

Create a file called .gitignore in the repo and add a list of file types & paths to it that you don’t want git to commit (private files you don’t want public).

23
Q

What does each commit reference?

A

The commits that come before and after it (except the first and last commits).

24
Q

What is the master (or main) branch?

A

The branch that everything else branches off of.

25
Q

What is HEAD?

A

A pointer that points to master initially but when you start a new branch, HEAD points to the most recent commit on that branch.

26
Q

Command to create a branch.

A

git branch

27
Q

What does the git branch command do without a branch name given to it?

A

Shows you what branch you’re on and where HEAD is pointing.

28
Q

Command to switch branches.

A

git switch

29
Q

Where is a branch created when the git branch command is used?

A

The location of HEAD is where a branch is made.

30
Q

How do you create a new branch and switch to it in a single command?

A

git switch -c

31
Q

Command to commit all changes at once.

A

git commit -a -m

32
Q

What does the checkout command do?

A

Lets you switch branches but also does a lot of others stuff. More functionality than git switch.

33
Q

Command to delete a branch.

A

git branch -d
(-D for force delete)

34
Q

What is merging and how does it work?

A

You work on various features and then merge them back to the master branch. You merge entire branches, not commits.

35
Q

Which branch do you need to be on to merge?

A

You move to the branch which is receiving the merge. You always merge from the current HEAD branch.

36
Q

Command to merge branchName to master.

A

Move to the master branch and type get merge

37
Q

What is a merge conflict?

A

When you alter the same line in different branches and try to merge them.

38
Q

Command to show you differences between your working directory & the staging area.

A

git diff

39
Q

Command to show staged & unstaged changes since last commit.

A

git diff HEAD

40
Q

Command to show only stage changes.

A

git diff –staged

41
Q

Command to show differences between specific files.

A

git diff file1 file2 …

42
Q

Command to show differences between branches

A

git diff branch1 branch2 …

43
Q

What is stashing?

A

This basically saves your changes when you want to switch branches without actually committing them.

44
Q

How to remove the most recently stashed changes & re-apply them to your working copy.

A

git stash pop

45
Q

In what order are stashes stored?

A

FILO

46
Q

Command to view the stash stack

A

git stash list

47
Q

Command to drop a particular stash

A

git stash drop stash@{index#}

48
Q

Command to clear entire stash

A

git stash clear

49
Q

What is detached HEAD?

A

HEAD usually point to the most recent commit on a branch. Detached head is when HEAD is not pointing to a terminal node (traveling back in time to make a new branch at that point)

50
Q

Command to reference commit x-amount before HEAD.

A

git checkout HEAD~x

51
Q

Command to discard changes you made to a file.

A

git checkout HEAD

52
Q

Command to remove a file from stage.

A

git restore –staged fileName.txt

53
Q

Say you made a couple commits on the master branch but you actually meant to make them on a separate branch instead. What is the command to undo those commits?

A

git reset will reset the repo back to the specific commit that the hash is from.

54
Q

If you want to reverse some commits that other people already have on their machines, use (revert/reset). If you want to reverse commits that you haven’t shared with others, use (revert/reset) and nobody else will be affected by it.

A

Revert, reset