Git Flashcards

1
Q

What is version control

A

Version control is a system that records changes to a file or set of files over time so that you can recall specific versions later

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

The Three States

A

Modified means that you have changed the file but have not committed it to your database yet.

Staged means that you have marked a modified file in its current version to go into your next commit snapshot.

Committed means that the data is safely stored in your local database.

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

default branch name

A

By default Git will create a branch called master when you create a new repository with git init. From Git version 2.28 onwards, you can set a different name for the initial branch.

To set main as the default branch name do:

$ git config –global init.defaultBranch main

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

help command git

A

If you ever need help while using Git, there are three equivalent ways to get the comprehensive manual page (manpage) help for any of the Git commands:

$ git help
$ git –help
$ man git-

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

git commands

A

git init : This creates a new subdirectory named .git that contains all of your necessary repository files — a Git repository skeleton
git add commands that specify the files you want to track,

You clone a repository with git clone

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

Tracked & untracked

A

Tracked files are files that were in the last snapshot, as well as any newly staged files; they can be unmodified, modified, or staged. In short, tracked files are files that Git knows about.

Untracked files are everything else — any files in your working directory that were not in your last snapshot and are not in your staging area. When you first clone a repository, all of your files will be tracked and unmodified because Git just checked them out and you haven’t edited anything.

As you edit files, Git sees them as modified, because you’ve changed them since your last commit. As you work, you selectively stage these modified files and then commit all those staged changes, and the cycle repeats.

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

Checking the Status of Your Files

A

he main tool you use to determine which files are in which state is the git status command

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

The rules for the patterns you can put in the .gitignore file are as follows:

A

Blank lines or lines starting with # are ignored.

Standard glob patterns work, and will be applied recursively throughout the entire working tree.

You can start patterns with a forward slash (/) to avoid recursivity.

You can end patterns with a forward slash (/) to specify a directory.

You can negate a pattern by starting it with an exclamation point (!).

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

git diff

A

That command compares what is in your working directory with what is in your staging area. The result tells you the changes you’ve made that you haven’t yet staged.

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

Removing Files

A

To remove a file from Git, you have to remove it from your tracked files (more accurately, remove it from your staging area) and then commit. The git rm command does that, and also removes the file from your working directory so you don’t see it as an untracked file the next time around.

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

Removing Files

A

To remove a file from Git, you have to remove it from your tracked files (more accurately, remove it from your staging area) and then commit. The git rm command does that, and also removes the file from your working directory so you don’t see it as an untracked file the next time around.

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

Moving files in git

A

Unlike many other VCSs, Git doesn’t explicitly track file movement. If you rename a file in Git, no metadata is stored in Git that tells it you renamed the file. However, Git is pretty smart about figuring that out after the fact — we’ll deal with detecting file movement a bit later.

Thus it’s a bit confusing that Git has a mv command. If you want to rename a file in Git, you can run something like:

$ git mv file_from file_to
and it works fine

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

Viewing the Commit History

A

git log

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

Undoing things

A

One of the common undos takes place when you commit too early and possibly forget to add some files, or you mess up your commit message. If you want to redo that commit, make the additional changes you forgot, stage them, and commit again using the –amend option:

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

Unmodifying a Modified File

A

git checkout – file

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

to unstage file

A

it says use git restore –staged …​ to unstage

17
Q

Unmodify a modified file

A

(use “git restore …” to discard changes in working directory)