Git Flashcards

1
Q

git init

A

Turns the working directory into the Git working directory and creates a repository

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

Repository

A

A folder whose contents are tracked by Git

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

.git folder

A

This folder contains all the files and folders required by Git to keep track of all the changes done to the files within this repo.

If you delete the “.git” folder, Git will not identify this folder as a repo nor track its contents. You will lose all of the historical changes.

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

git status

A

if you want to see what is being tracked by Git within a repository

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

git add .

A

Stages the files in this directory to be committed

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

git commit -m “message”

A

commits your work to your local repository with the message given

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

Rebasing

A

essentially takes a set of commits, “copies” them, and plops them down somewhere else.

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

HEAD

A

HEAD is the symbolic name for the currently checked out commit – it’s essentially what commit you’re working on top of.

HEAD always points to the most recent commit which is reflected in the working tree.

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

Specifying commits with the caret operator

A

Each time you append that to a ref name, you are telling Git to find the parent of the specified commit.

So saying main^ is equivalent to “the first parent of main”.

main^^ is the grandparent (second-generation ancestor) of main

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

Using the ~ operator to move commits

A

The tilde operator (optionally) takes in a trailing number that specifies the number of parents you would like to ascend.

git checkout main~3

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

git branch -f main HEAD~3

A

Moves the pointer for main to 3 commits before the current HEAD

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

git reset HEAD~1

A

Points HEAD back one commit

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

git revert HEAD

A

creates a new commit that is the same as the one directly before HEAD

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

git cherry-pick <Commit1> <Commit2> <...></Commit2></Commit1>

A

It’s a very straightforward way of saying that you would like to copy a series of commits below your current location (HEAD)

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

git cherry-pick c1

A

git cherry-pick will plop down a commit from anywhere in the tree onto HEAD (as long as that commit isn’t an ancestor of HEAD).

in this case c1

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

git tag v1 c1

A

Tags c1 with the label v1 permanently

17
Q

git rebase -i HEAD~3

A

Gives you an interactive choice of both which of the last 3 commits you’d like to keep and in what order, and appends them to the commit 3 above head.

Additionally the latest point in that branch (and HEAD) is at the new latest commit you appended

18
Q

git describe <ref></ref>

A

If you don’t specify a ref, then HEAD is used

The output looks like:

<tag>_<numCommits>_g<hash>

Where tag is the closest ancestor tag in history, numCommits is how many commits away that tag is, and <hash> is the hash of the commit being described.
</hash></hash></numCommits></tag>