Console Flashcards

1
Q

show files in the current directory

A

ls (name: list. list files)

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

ls - additional commands

A
  • l (prints long form of file list)

- a (show all files, including hidden files)

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

ls - l

A
prints long form of file list
drwxrwxr-x
r: read
w: write
x: execute
  • first rwx - permissions of the creator
  • second rex - permissions of a group
  • last r-x - permission for everyone else
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

what a folder is called in a console

A

directory

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

show you your current directory

A

pwd - print working directory

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

shortcut to home directory

A

~ (tilda)

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

move to a different directory

A

cd - change directory

you don’t need start with a / if you are moving to relative directory from where you currently are.

if you do an absolute path, you have to start with /user…

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

move up a directory level

A

cd ..

to move two levels up: cd ../..

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

a program that displays the content of a file

A

less

need to hit the “q” key to exit out of the less program

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

prints the contents of one or more files to the console

A

cat

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

a simple text editor in the console

A

nano

shortcuts use the ^ which is actually the control button

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

how to move or rename a file or directory

A

mv (move)
takes two arguments:
1) what do we want to move
2) where we want to move it

Renaming:
$ mv hello.txt hi.txt (this is same as renaming it)

Moving directories:
$ mv hi.txt documents/
(this is moving it because documents is a directory)

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

represents our current directory

A

.
(dot)

$ mv documents/hi.txt .
this would move it up one directory (my current directory)

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

copies a file or directory

A

cp

works the same as move -

1) what do we want to copy
2) where we want to copy it to?

for copying a directory though you have to use -r (recursive) which will copy of the document within the directory as well. example:
$ cp -r documents docs
(this will copy the documents folder and call it docs (with all of the

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

removes files or directories

A

rm
be careful of using remove because there is no going back in console.

you can’t remove a directory without an -r just like copy because you need to recursively remove all of the files and sub-directories in within the directory as well

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

how to create a directory (including nested directories)

A

mkdir
(make directory)

to create nested directories
use the -p documents/notes/console/part1 (the -p allows us to create as many sub directories as needed)

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

repository

A

a collection of all the different versions and files of a project

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

committing

A

git commit

other commit commands:
git commit -a -m

a - means that all changes to the files in the repository will be committed.

m - means that you can add the commit description message directly to the commit command

when you tell the version control system that you are done with a version and ready for the next

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

create a repository

A

git init [name of project]

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

how to add a file to the repository so that i can be tracked

A

git add [file name to be added to the repository]

you can also use “git .” which will stage all changes to the files in that directory.

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

how to get the status of a commit

A

git status

this will show you the staging area and tell git what you want to commit (if you do or don’t want to commit all changes)

22
Q

get the history of your git repository

A

git log

(latest commits start at the TOP)

To make it on one line per commit, you can use the:

git log –pretty=oneline

23
Q

Move to (look into the details) of a commit in the repository and then return to the latest

A

To check out a previous commit

git checkout [first 5 or 6 characters of the commit number]
(note: that you can make changes here but that is dangerous.

To return to the latest versions
git checkout master (or git checkout HEAD)

  • ‘master’ is the name of the default branch. By checking out a branch by name, you go to the latest version of that branch.
  • if you use git checkout HEAD~! it is a special commit identifier in git; it stands for the previous commit (not the one we just made, but the one before that).

Also, the checkout command can be used to discard changes

24
Q

how to look at the difference between two commit (what has changed)

A

git diff [first commit num] [second commit nun]

25
Q

how to create a branch to work on a new feature

A

git branch [branch/feature name]

note: no “” are needed/

you need to checkout to actually move to that branch, otherwise you will stay on master

if you want to do them together you can use

$ git checkout -b [branch_name]

the b is for branch, so this will create a new branch and take you directly there (shortcut)

26
Q

what commits are included when you create a new branch?

A

the new branch will be a copy of whatever branch you are currently in (either master or a different branch you may be in)

27
Q

how to delete a branch

A

$ git -D [branch name]

you can’t delete it if you are inside of it though, you should move to the master first

28
Q

merging branches

A

go the the master branch and then:

$ git merge [branch_name]

when you merge a branch to the master, not only does it merge the latest commit of that branch, but also all other previous branch commits as well. It makes one cohesive timeline on the master

29
Q

conflicts of auto-resolvable merging

A

if there is a conflict and git can merge automatically, it will create a new commit on the master that resolves the conflicts and then merges the changes. the original branch remains unchanged and you can still check it out

30
Q

conflicts of non-auto-resolvable merging

A

the merge will tell you that there is a conflict. you can then go into the file in conflict and nano will tell you where the conflict between the two files are. you have two options:

1) remove the conflict markers and keep both changes
2) remove the conflict markets and change it to however you want it to be

31
Q

how to copy a repository and store it in another location (on same computer or remotely)

A

$ git clone [current repository name, including directory path to get to the repo] [new copied repository name]

32
Q

how are the cloned repositories connected to the master branch?

A

the cloned branch is a copy of the master branch but a new connection is added to it called remote. And the master branch is added as a remote “origin”.
You can see the remote repositories by running:
$ git remote
which will give you a list of the remote repos

the master branch remains unchanged though unless you run the:
$ git remote add [a name you want to call the existing clone] [the branch you want to add, including the directory/network location]

33
Q

how to send the changes from a branch on a remote repo to another repository?

A

$ git push [repository name you want to add it to] [new name of the branch to be added to the repository that you will be pushing to]

if you don’t provide a repository name, then it will assume that it is origin

if the branch you are pushing to another repository doesn’t exist there, you have to create a new branch on that repository

34
Q

how to update a remote repo with the changes from the origin or other repo

A

$ git pull [origin or other repo name] [branch you want to pull in changes from from the other repo]

35
Q

conflicts from pulls

A

open file in conflict and resolve

36
Q

How to you unstage changes for a commit?

A

Git reset

37
Q

How do you save and exit from GIT_EDITOR?

A

Look up answer!

38
Q

Shortcut for adding all the changes to the files in the current directory and below?

A

git add .

But since it adds everything, it’s a really good idea t check the gig status before doing a add ., just to make sure you don’t add any file that is not intended.

39
Q

Git shortcut (custom added to the .gitconfig file in the home directory)

A
co - checkout
ci - commit
st - status
br - branch
hist- log (with fancy display)
type - cat-file -t
dump - cat-file -p
40
Q

How to tag previous commits with customer names and view in the history/log all of the tag names on all commits:
git hist master –all

A

git tag [tag name ie v1 or v1-beta]

A shortcut to move to the commit prior to) a certain tag:
git commit v1^

The ^ moves it to the parent commit

41
Q

How to revert local changes before they have been put on staging

A

git checkout [file name]

42
Q

How to undo local changes after out on staging but before committing

A

git reset HEAD [filename]
git checkout [filename]

You can do git checkout to confirm if changes have been reverted (and the actual file itself)

43
Q

How to undo committed changes

A

git revert HEAD [optionally the tag name or hash if you are going back more than just one commit]
This will create a new commit with the one immediately before

Git revert reset –hard [tag or hash value of the commit you want to revert to]
This will allow you to jump to a specific commit and the other branches that you jumped over will no longer appear in history (unless you use git log –all)

git tag -d [tag name]
This will remove it completely so that git log -a will also not show it. This will delete it (signaled for garbage collecting)

44
Q

How to amend a file a file from the previous commit?

A

git commit –amend -m “[commit message]”

This erases the previous commit with changes (similar to reverting to the previous and then replacing it)

45
Q

How to move a repository file (and track in git)

A

mkdir [new directory name]
git mv [filename] [new location]

Git status will show you it was created to new location and the file in the original location was deleted

Alternatively:
mkdir [new directory]
mv [filename] [directory]
git add [directory/filename]
git rm [filename]
46
Q

what is the lowest level of the command line directory?

A

Root. simply / (the hard drive)

47
Q

how to save and exit the text editor in terminal (VIM)

A

hit “esc” then :wq (w for write and q for quit)

alternatively, you can just to :x

48
Q

what is Forking?

A

A means for getting a personally owned repository that you wouldn’t have direct write access to. Flow for forking:

1) Fork from owner’s Repo
2) Get the HTTP address from new Fork
3) git clone [HTTP address] [Name of Clone]
4) git branch [branch name]
5) make changes and commit them
6) push the changes back to the new Forked repo with: git push -u origin [branch name]
7) enter credentials
8) Look for new branch in branch list
9) Pull request button appears (context sensitive) and it starts the process of offering this branch to the master repository
10) Identify where you want the branch to be added (mast for example), and from where it is coming from (your new branch)

49
Q

What is a pull request?

A

providing the changes you have made on a named branch back to a repository that you forked from but don’t have direct write access to

50
Q

how to make a comma separated string of the items in an array

A

array.join(“,”);