Git Flashcards

1
Q

To restore deleted and staged files

A

git reset HEAD followed by

git checkout HEAD

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

to see the remotes associated with your local repository.

A

git remote -v

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

git diff compares your working tree

A

to the staging area

git diff –staged to compare to staging area

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

git log -p

A

to see every detail of your commits, such as the actual changes, or diff, of each commit.

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

The working tree is

A

the collection of project files that you work with directly.

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

Git thinks about the files in your working tree as being in three distinct states:

A

unmodified, modified and staged.

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

/.html matches

A

all files with an .html extension, but only in subdirectories of your project.

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

Graphical views of your repository

A

git log –graph

git log –oneline –graph

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

o tell Git to show you the complete history of everything it knows about

A

git log –oneline –graph –all

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

Searching Git history commands

A
git log --author=crispy8888 --oneline
git log --grep=ideas --oneline
git log --oneline books/book_ideas.md
git log --oneline --stat books
books - directory 
To see changes in directory
git log -S"Fortran"
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Find all of the commits in your code that deal with the term “Fortran”

A

git log -S”Fortran”

git log -S”Fortran” -p (with details)

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

to see all local branches.

A

git branch

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

brings the commits from the remote repository and merges them with your local commits.

A

git pull

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

pulls all of the commits down from the remote repository to your local
one.

A

git fetch

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

You can’t push to a remote that has

A

any commits that you don’t have locally, and that Git can’t fast-forward merge.

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

to add a remote to your local repository.

A

git remote add origin

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

to push the local commits in your repository to your remote, and to start tracking your local branch against the remote branch.

A

git push–set-upstream origin master or git push -u origin master

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

How Git reconstruct a branch, based on a single commit hash step by step

A

You switch to a named branch, which is a label that references a commit hash.

Git finds that commit object by its hash, then it gets the tree hash from the commit object.

Git then recurses down the tree object, uncompressing file objects as it goes.

Your working directory now represents the state of that branch as it is stored in the repo.

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

Gits the most common objects

A

Commits: Structures that hold metadata about your commit, as well as the pointers to the parent commit and the files underneath.

Trees: Tree structures of all the files contained in a commit.

Blobs: Compressed collections of files in the tree.

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

git rev-parse

A

will translate a short hash into a long hash

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

git cat-file

A

will show you the pertinent metadata about an object.

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

git status -sb

A

gives a concise view of the state of your working tree.

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

starts an interactive rebase operation.

A

git rebase -i

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

You can move lines around in the rebase script to

A

reorder commits.

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

What cloning repository automatically do?

A

Cloning a repository automatically creates a hidden .git directory, which tracks the activity on your local repository.

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

What Forking do?

A

Forking creates a remote copy of a repository under your personal user space.

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

Git thinks about the files in your working tree as being in three distinct states

A

Unmodified •
Modified•
Staged

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

With git add .

A

to put everything from your working tree into the staging area

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

How Git views your working tree?

A

At its core, Git really only knows about files, and nothing about directories. Git thinks about files as string that point to entities Git can track.

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

How to commit an empty directory?

A

placeholder file. The usual convention is to create a hidden, zero-byte .keep file inside the directory you want Git to “see.”

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

A commit is essentially

A

a snapshot of the particular state of the set of files in the repository at a point in time

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

git status

A

shows you the current state of your working tree.

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

git add

A

lets you add changes from your working tree to the staging area.

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

git add .

A

adds all changes in the current directory and its subdirectories.

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

git add /*

A

lets you add all changes in a specified directory.

36
Q

git diff

A

shows you the difference between your working tree and the staging area.

37
Q

git diff –staged

A

shows you the difference between your staging area and the last commit to the repository.

38
Q

git commit

A

commits all changes in the staging area and opens Vim so you can add a commit message.

39
Q

git commit -m “”

A

commits your staged changes and includes a message without having to go through Vim.

40
Q

git log

A

shows you the basic commit history of your repository.

41
Q

git log -p

A

shows the commit history of your repository with the corresponding
diffs.

42
Q

The general philosophy is that a commit should be

A

a logical collection of changes that make sense as a unit — not just “the latest collection of things I updated that may or may not be related.”

43
Q

what is HEAD?

A

HEAD is simply a label that references the most recent commit

44
Q

git reset HEAD

A

use HEAD as a reference point, restore the staging area to that point

45
Q

staging area

A

The staging area lets you contruct your next commit in a logical, structure fashion.

46
Q

git reset HEAD

A

lets you restore your staging environment to the last commit state.

47
Q

How I should move/delete files in a repository?

A

With git commands

git rm
git mv

48
Q

git mv

A

moves files around and stages the change, all in one action.

49
Q

git rm

A

removes files from your repository and stages the change, again, in one
action.

50
Q

global .gitignore

A

You can find where your global .gitignore lives with the command git config – global core.excludesfile ~/.gitignore_global.

51
Q

.gitignore lets you

A

configure Git so that it ignores specific files or files that match a certain pattern.

52
Q

*.html in your .gitignore matches

A

on all files with an .html extension, in any directory or subdirectory of your project.

53
Q

! in .gitingnore

A

negates a matching rule.

54
Q

You can have multiple .gitignore files inside various directories of your project to

A

override higher-level matches in your project.

55
Q

Limiting results git log

A

git log -3

56
Q

Git log each commit in one line

A

git log –oneline

57
Q

git shortlog

A

This is a nice way to get a summary of the commits, perhaps for including in the release notes of your app.

58
Q

A commit in Git includes information about

A

the state of the files in your repository, along with metadata such as the commit time, the commit creator, and the commit’s parent or parents.

59
Q

A branch in Git is simply

A

a reference to a particular commit by way of its hash.

60
Q

to create a branch

A

git branch

61
Q

to switch to a local branch, or to checkout and track a remote branch.

A

git checkout

62
Q

to delete a local branch.

A

git branch -d

63
Q

to see all local and remote branches.

A

git branch –all

64
Q

to create and switch to a local branch in one fell swoop.

A

git checkout -b

65
Q

git pull is actually two commands in disguise:

A

git fetch & git merge

66
Q

takes your local commits and synchronizes the remote repository with
those commits.

A

git push

67
Q

merges the commits from the remote into your local repository.

A

git merge

68
Q

Can you have multiple remotes?

A

Yes

You can pull commits from multiple remotes into your local repository and merge them as you would commits from any other branch or remote.

69
Q

to set up a Git repository.

A

git init

70
Q

to create the first commit on your new repository.

A

Use git add followed by git commit

71
Q

create mode in git

A

is simply Git telling you what file permissions it’s setting on the files added to the repository.

72
Q

What commit object stores?

A

A commit object stores the metadata about a commit, such as the parent, the author, timestamps and references to the file tree of this commit

73
Q

A tree object is

A

a collection of references to either child trees or blob objects.

74
Q

Blob objects are

A

compressed collections of files; usually, the set of files in a particular directory inside the tree.

75
Q

git config merge.conflictstyle diff3

A

provides a three-way view of the conflict, with the common ancestor, “their” change, and “our” change.

76
Q

Rebasing is a great technique over merging when you want

A

to keep the repository history linear and as free from merge commits as possible.

77
Q

To rebase your current branch on top of another one, execute

A

git rebase .

78
Q

To resume a rebase operation after resolving conflicts and staging your changes, execute

A

git rebase –continue.

79
Q

To skip rebasing a commit on top of the current branch, execute

A

git rebase –skip.

80
Q

Should I do rebasing locally or on remote?

A

Locally

81
Q

Interactive rebases in Git let you

A

create a “script” to tell Git how to perform the rebase operation

82
Q

The pick command means

A

to keep a commit in the rebase.

83
Q

The squash command means

A

to merge this commit with the previous one in the rebase.

84
Q

The reword command lets you

A

reword a particular commit message.

85
Q

Rebasing creates

A

new commits for each original commit in the rebase script.

86
Q

Squashing lets you

A

combine multiple commits into a single commit with a new commit message. This helps keep your commit history clean.

87
Q

Gitignore After the Fact

A

Mastering git book