Version Control with Git [Udacity]

59 flashcards · Computer Science · by Kshitij Sabale

  1. git show x, where x is first 7 chars of the commit's SHA 1 --stat 2 -p or --patch 3 -w

    What command is used to display log of only one commit? And what are the most common flags of it: 1 to show the how many files were changed and the number of lines that were added/removed 2 displays the actual changes that have been made to the commit, icluding; this the default, but if --stat is used, the patch won't display, so pass -p to add it again 3 to ignore changes to whitespace

  2. git config --global merge.conflictstyle diff3

    <<<<<<< HEAD THIS IS USEFUL ||||||| merged common ancestors This is useful ======= This is really useful >>>>>>> c2392943..... Adds a ||||||| marker and the original text before the ======= marker. The default is "merge", which shows a <<<<<<< conflict marker, changes made by one side, a ======= marker, changes made by the other side, and then a >>>>>>> marker.

  3. git config --global core.editor "code --wait"

    How to associate Visual Studio Code with Git?

  4. git config --list

    How to check all the keys available in the Git config file?

  5. git init [project name]

    Create a new local repository. If [project name] is provided, Git will create a new directory name [project name] and will initialize a repository inside it. If [project name] is not provided, then a new repository is initialized in the current directory.

  6. git clone https://... (optionally, u could add the folder name after the url, to clone the repository into that folder, e.g. use another name of the repository locally)

    If you want to get a copy of an existing Git repository from a romete web server — for example, a project you’d like to contribute to — the command you need is ? (e.g., used to create an identical copy of an existing repository)

  7. git status

    List which files are staged, unstaged, and untracked

  8. git log (to leave Less text editor, use q) git log -n x, where x is the last number commits

    1 The command which is used to display all of the commits of a repository. By default, this command displays: the SHA the author the date and the message 2 limits list to last N number of commits

  9. git log --stat

    What flag is used to alter how git log displays information, so that this command: displays the file(s) that have been modified in the commit displays the number of lines that have been added/removed in the commit displays a summary line with the total number of modified files and lines that have been added/removed in the commit

  10. git config --global user.name "x", where x is <Your-Full-Name> and git config --global user.email "x", where x is <Your-Email>

    1 Set the name that will be attached to your commits and tags 2 Set the e-mail address that will be attached to your commits and tags

  11. git add . (in a regular way it would be used as git add x x ... xN, where x, xN are the names of the files

    Which command is used to move all files (including all nested files and directories!) from the Working Directory to the Staging Index

  12. git rm --cached x, where x is the name of the file

    Which command is used to unstage a file if it has'n't been committed yet? Also, this used the word "unstage". The act of moving a file from the Working Directory to the Staging Index is called "staging". If a file has been moved, then it has been "staged". Moving a file from the Staging Index back to the Working Directory will unstage the file. If you read documentation that says "stage the following files" that means you should use the git add command.

  13. .gitignore

    What file is used to tell Git about the files that Git should not track? This file should be placed in the same directory that the .git directory is in.

  14. What does [abc] wildcard does in globbing? Is it case-sensitive?

    matches one character given in the bracket For example, [CB]at matches Cat or Bat, but does NOT matches: cat or bat

  15. What does the [a-z] wildcard does in globbing?

    Match one occurrence of a character between a and z; alternatively, there could be [0-9], [4 and 89], u name it. For example, Letter[0-9] matches: Letter0, Letter1, Letter2 up to Letter9 but does NOT matches: Letters, Letter or Letter10

  16. What does the ** wildcard does in globbing?

    matches nested directories For exampe, a/**/z matches: a/z a/b/z a/b/c/z

  17. git tag -a x, where x is the name of the tag If you don't provide the flag, then it'll create what's called a lightweight tag.

    What command is used to create an annotated tag to the most recent commit? Annotated tags are recommended because they include a lot of extra information such as:the person who made the tag the date the tag was made a message for the tag Because of this, you should always use annotated tags.

  18. git tag

    What command is used to display all tags that are in the repository?

  19. git tag -d x, where x is the name of the tag

    How a tag can be deleted?

  20. git commit -m "x", where x is used as the commit message. Be aware that you can't provide a description for the commit, only the message part

    If the commit message you're writing is short and you don't want to wait for your code editor to open up to type it out, you can pass your message directly on the command line with ?

  21. git branch

    Which command is used to list all branches?

  22. git checkout x , where x – the sha of the required commit

    Перемістити HEAD на потрібний коміт

  23. git branch -dr x/y x – the alias of your remote repo y – one of branch's name on your remote repo

    Delete a branch on a remote repo

  24. If you ask Git to ignore "be?rs", which of the following filenames will be ignored? bears beavers BeArS beers boars

    ? matches 1 character, so the answer is: bears beers *BeArS - though ? is not casesensitive, the rest of characters are compared casesensitively

  25. git reset --mixed HEAD^ git-reset is about updating your branch, moving the tip in order to add or remove commits from the branch. This operation changes the commit history.

    !!! THIS OPERATION CHANGES THE COMMIT HISTORY !!! Moves the HEAD pointer to the previous commit PRESERVING ALL YOUR CHANGES of the current commit BUT NOT ADDING them to the staging index of the previous commit, and REMOVES the current commit from the branch history

  26. git branch x

    How to create a branch called "x" and pointed to the latest commit?

  27. git checkout x, where is is the name of the brance

    What command is used to switch between brances? It's important to understand how this command works. Running this command will: remove all files and directories from the Working Directory that Git is tracking (files that Git tracks are stored in the repository, so nothing is lost) go into the repository and pull out all of the files and directories of the commit that the branch points to

  28. git branch -d x, where x is the name of the branch

    What command is used to delete a branch? Things to note: you can't delete a branch that you're currently on Git won't let you delete a branch if it has commits on it that aren't on any other branch (meaning the commits are unique to the branch that's about to be deleted)

  29. git checkout -b x y, where x is the name of the newly-created branch, y is the branch name (the most recent commit in that branch) or a commit's SHA which the newly-created brach will stem from

    How to create a branch, switch to it, and, at the same time, make this new branch to stem from a specific branch, all in one command?

  30. git log --oneline --graph --all The --graph flag adds the bullets and lines to the leftmost part of the output. This shows the actual branching that's happening. The --all flag is what displays all of the branches in the repository.

    We can't see other branches in the git log output unless we switch to a branch. How to see all branches at once in the git log output?

  31. git merge x, where x is the name of the branch to be merged into into the branch that's currently checked out

    What command is used to combine two branches? When a merge happens, Git will: look at the branches that it's going to merge look back along the branch's history to find a single commit that both branches have in their commit history combine the lines of code that were changed on the separate branches together make a commit to record the merge

  32. git show HEAD^ or HEAD~ or HEAD~1

    How to reference the parent commit of the current commit?

  33. git show SHA^2, where SHA is the SHA of a merge commit

    How to reference the second parent of a merge commit?

  34. 1 git show HEAD^^ or HEAD~2 2 git show HEAD^^^ HEAD~3

    How to reference: 1 grandparent of the current commit 2 great-grandparent of the current commit

  35. git show HEAD^^^2 or HEAD~2^2

    Hot to reference the second parent of the grandparent of a the current merge commit?

  36. git reflog

    Git does keep track of everything for about 30 days before it completely erases anything. What command is used to access this content?

  37. git branch backup

    What command may be used, for example before doing any resetting, to create a reserve-branch on the most-recent commit so that u could get back to the commits if u had made a mistake?

  38. git rebase x, where x is the name of branch on which you put the current branch

    How to take all the changes that were committed on one branch and replay them on a different branch? This way of merging makes for a cleaner history. If you examine the log of a rebased branch, it looks like a linear history: it appears that all the work happened in series, even when it originally happened in parallel.

  39. git fetch <remote>

    Downloand all changes from a remote repository <remote> (commits, files, and refs) into your local repo, BUT don't merge/integrate them into HEAD. Fetching is what you do when you want to see what everybody else has been working on. ... This makes fetching a safe way to review commits before integrating them with your local repository.

  40. git push <remote> <branch> It's the counterpart to git fetch , but whereas fetching imports commits to local branches, pushing exports commits to remote branches.

    What command is used to upload local repository content to a remote repository?

  41. (1) git log --oneline (2) git log --pretty=oneline

    This command (1): lists one commit per line shows the first 7 characters of the commit's SHA shows the commit's message (2) the same but shows all the 40 charachters of the commit's SHA

  42. 1 git log --pretty=oneline --max-count=2 2 git log --pretty=oneline --since='5 minutes ago' 3 git log --pretty=oneline --until='5 minutes ago' 4 git log --pretty=oneline --author=x, where x is sb's name

    How to make git log show the list of commits with their whole SHA and: 1 the latest two 2 all the commits made in the past 5 minutes 3 all the commits made until the past 5 minutes 4 all the commits made by a certain person

  43. gitk

    How to open a graphical history viewer? Think of it like a powerful GUI shell over git log and git grep. This is the tool to use when you're trying to find something that happened in the past, or visualize your project's history.

  44. git pull --rebase

    What command ensures that changes made to the local repo are put on top of the changes made in the remote? (коротка форма для git fetch а потім git rebase)

  45. git rm x, where x is the name of the file

    How to remove a file from the current repository?

  46. git remote show x, where x is the name of the remote repo (u can get it with git remote)

    Shows information about a remote repo as follows:

  47. git pull <remote> <branch>

    Download all changes (commits, files, and refs) from a remote repository and immediately merge/integrate them into HEAD. просто коротша форма для git fetch а потім git merge Merging remote upstream changes into your local repository is a common task in Git-based collaboration work flows.

  48. git log -p (or --patch)

    Which flag does the git log have that adds the following to the default output: displays the files that have been modified displays the location of the lines that have been added/removed displays the actual changes that have been made

  49. git branch -D x, where x is the name of the branch, and the flag MUST be CAPITALIZED

    Since Git won't let you delete a branch if it has commits on it that aren't on any other branch, what command is used to force deletion of a branch?

  50. git log --pretty=format:"%h %ad %cd | %s %d [%an]" --graph --date=short --since='7 days ago'

    Hot to show commits' log as follows: defining the format + SHA + date when the author made the commit + date when a commiter made the commit + commit commet + commit decorations (e.g. branch heads or tags) + the author in brackets + display the commit tree in the form of an ASCII graph layout + keeps the date format short and nice + all the commits made in the past 7 days

  51. git revert x, where x is the SHA of commit to revert

    What command is used to reverse a previously made commit? This command: will undo the changes that were made by the provided commit creates a new commit to record the change Використовується для більш складних виправлень, які знаходяться **не в останньому коміті** (або якщо ви вже завантажили свої зміни через push). Це дасть змогу взяти всі зміни, які були у коміті, відмінити їх, і створити новий комміт. Коли ви повертаєтесь до старих комітів, майте на увазі, що виникає ризик отримати т.з. "кон…

  52. git commit --amend

    What command: change the latest commit: let you provide a new commit message for the latest commit if your Working Directory is clean (meaning there aren't any uncommitted changes in the repository) add forgotten files (or changes to files) to the latest commit: edit the file(s), save the file(s), stage the file(s), and run this ? command Be cautious when using --amend on commits shared with other team members. Amending a commit that is shared with another user will potentially require confusin…

  53. samples/*.jpg

    So if all of the 50 images are JPEG images in the "samples" folder, what line could we add to .gitignore to have Git ignore all 50 images.

  54. git remote -v, where -v stands for "verbose"

    Print the list of bookmarked repository names and additionally, the corresponding repository URL

  55. git remote add x y, where x – an alias for your remote repo y – url of your remote repo: https://github.com/...

    Зв'язує наш локальний репозиторій з репозиторієм на GitHub і дає кличку <shortname> останньому. Проект може мати безліч дистанційних репозиторіїв одночасно. Для того, щоб відрізнити їх один від одного ми даємо їм різні клички/назви. Традиційно основний дистанційний репозиторій в git називають origin.

  56. git reset --hard HEAD^ git-reset is about updating your branch, moving the tip in order to add or remove commits from the branch history, and possibly updating the index (resetting it to the tree of <commit>) and the working tree depending on <mode>.

    !!! THIS OPERATION CHANGES THE COMMIT HISTORY !!! Erases the latest commit – moves the HEAD pointer to a previous commit and DISCARDS all changes (both in the staging index and in working directory) of the latest commit. EXAMPLE: You can use it, for example, to undo the merge if you make a merge on the wrong branch

  57. git reset HEADx, where x is the required reference (^, ^^, ^2, etc.) git-reset is about updating your branch, moving the tip in order to add or remove commits from the branch history, and possibly updating the index (resetting it to the tree of <commit>) and the working tree depending on <mode>. *since <mode> (--soft, --mixed, --hard) is here ommited, the command defauts to --mixed

    !!! THIS OPERATION CHANGES THE COMMIT HISTORY !!! How to move the HEAD pointer to a referenced commit back in history REMOVING commits from the branch?

  58. git reset --soft HEAD^ git-reset is about updating your branch, moving the tip in order to add or remove commits from the branc hhistory, and possibly updating the index (resetting it to the tree of <commit>) and the working tree depending on <mode>.

    !!! THIS OPERATION CHANGES THE COMMIT HISTORY !!! Moves the HEAD pointer to the previous commit ADDING ALL YOUR CHANGES of the current commit to the staging index of the previous commit, and REMOVES the current commit from the branch history

  59. git diff

    What command can be used to see changes that have been made but haven't been committed, yet? This command displays: the files that have been modified the location of the lines that have been added/removed the actual changes that have been made