* Shell :PROPERTIES: :ANKI_DECK: soft-eng::shell :END: ** Is it true that =git add= is a multi-purpose command? if so, what are some things it can do? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763629959831 :ANKI_NOTE_HASH: fe615aef9dbd7c394a4c8bf596fad542 :END: True. it can track new files, stage files, and mark merge-conflicted files as resolved. it may also be able to do more things. ** What is the checksumming algorithm used by Git? What is the length of the values? What are the value strings composed of? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763628836314 :ANKI_NOTE_HASH: 608c9a74473399a2a0094da8139def49 :END: SHA1 hash. 40 length. Hex; i.e. 0-9 + a-f ** What are the three main states files can reside in? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763628836317 :ANKI_NOTE_HASH: 5e8bbf9a43e1ae84776e8224f35c9fa0 :END: 1. modified 2. staged 3. committed ** What does the staging area look like? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763628836319 :ANKI_NOTE_HASH: 12608141804ad6b022cae76e4d230d3b :END: it is a _file_ called *index*. ** What are the three scopes of =git config= and where are each of the configuration files stored? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763628836321 :ANKI_NOTE_HASH: b7f1f6f7c6c9bc76f1fd464da5381a39 :END: - =--system= | all users: =/etc/gitconfig= - =--global= | current user; all repos: =~/.gitconfig= or =~/.config/git/config= - =--local== | =.git/config= per repo control ** Does =/etc/gitconfig= trump =.git/config=? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763628836322 :ANKI_NOTE_HASH: ea720bea54cb1e01bc87ff13f837c3ec :END: No. local trumps global which trumps system. This is also the case for configuration files more generally. ** What command can you use to check the git configuration settings? What about a specific key? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763628836324 :ANKI_NOTE_HASH: 242c21910ef621a9f5a42d2abf25887f :END: =git config --list= =git config = ; where key can be something such as =user.name= or =user.email=, =core.editor=, etc. ** What are the two types of files from gits' perspective? What kind of files belong in each type? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763628836325 :ANKI_NOTE_HASH: e13f96657fe8dc3afdc5ba9a3d6b7af7 :END: 1. *tracked:* things previously staged; newly staged files. - can be modified, unmodified or staged 2. *untracked:* everything else. the stuff git doesn't know about. ** How to =git add= recursively? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763628836327 :ANKI_NOTE_HASH: fa12f6763a70b41b512c574d6eb00160 :END: trick question; =git add= automatically adds directories recursively. ** What does =git add= do? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763628836328 :ANKI_NOTE_HASH: 4b038b8e586d86fc0331e87b400be389 :END: it begins /tracking/ the file and stages it for committing. it is multi-purpose and can do even more. think of it as "add precisely this content to the next commit" ** How to get a short git status? what do the LHS columns mean here? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_PREPEND_HEADING: t :ANKI_NOTE_ID: 1763629926820 :ANKI_NOTE_HASH: ea4c345522aec8c86c63faa4362eefcf :END: #+BEGIN_SRC bash $ git status -s M README MM Rakefile A lib/git.rb M lib/simplegit.rb ?? LICENSE.txt #+END_SRC *** Back =git status --short= or =-s=. - =m= : modified - =mm= : modified, staged, modified - =a= : added to staging - =??= : untracked ** What files do =*.[oa]= and =*.~= ignore in the =.gitignore=? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763628836331 :ANKI_NOTE_HASH: d8eae7d11e4bcd05be2ec4c22a0c2631 :END: files ending with =.o= OR =.a= and files ending with =.~=. ** How do you write comments in =.gitignore= file? how do you specify a directory to ignore? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763628836333 :ANKI_NOTE_HASH: e0818fc89cb844458eb86abbb9fb3230 :END: =#= end the directory name with =/= note, unless you add the prefix slash, it will ignore that named directory at all levels! the prefix slash means 'not recursively' ** What are glob patterns? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_PREPEND_HEADING: t :ANKI_NOTE_ID: 1763628836334 :ANKI_NOTE_HASH: e00b17127c0e0549fca5aa4244059dd3 :END: *** Front What do these ones do? - =*= - =[abc]= - =?= - ~[0-9]~ - ~a/**/z~ *** Back they are simplified regular expressions. - =*= : matches zero or more characters. - =[abc]= : matches any character inside the brackets - =?= : a single character - ~[0-9]~ : matches any character between the range - ~a/**/z~ : nested directories; matches ~a/b/c/z~, ~a/z~, ~a/b/z~, etc. ** What do the following instructions do in a =.gitignore= file? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_PREPEND_HEADING: t :ANKI_NOTE_ID: 1763629926825 :ANKI_NOTE_HASH: a1626558b3c2e7ad41458da861b3d3c7 :END: - =*.a= - =!lib.a= - =/TODO= - =build/= - =doc/*.txt= - =doc/**/*.pdf= *** Back - ignore all =*.a= files - but track =lib.a= - only ignore =TODO= file in current directory. not =subdir/TODO=. recall that prefix =/= avoids recursivity - ignore all files in _any_ directory named =build= - ignore =doc/notes.txt=, but not =doc/server/notes.txt= - ignore all =.pdf= files in =doc/= and subdirs ** Can a repo only have 1 =.gitignore= file? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763628836337 :ANKI_NOTE_HASH: 965a2bea250dfd0c06434dbad6919cf4 :END: no, it can have *one* in each subdirectory if required. ** What does =git diff= do? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763628836339 :ANKI_NOTE_HASH: 4a6430d658452c9f7ac9970a8c36c405 :END: it compares what is in your working directory with what is in your staging area. ** How can you use =git diff= to compare your staged changes to the last commit? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763628836340 :ANKI_NOTE_HASH: c92ba41f56f2335f4d5ea79c8ae9091c :END: =git diff --staged= ** What is the difference between =git diff --staged= and =git diff --cached=? What do they do? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763628836341 :ANKI_NOTE_HASH: 6032aea15bec94d15d9347e34385e524 :END: they're synonyms! shows the /diff/ between last commit and what is staged ** What does =-v= do in =git commit=? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763628836343 :ANKI_NOTE_HASH: 75397ad5a9f1f1f82424f3e3101f5bb9 :END: adds a =git diff= to the commit popup so you can see exactly what you are committing. ** How can you skip the staging area? What is there to be careful of? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763628836344 :ANKI_NOTE_HASH: 05c572a5cc96b2713275ea0ede4ff83a :END: =git commit -a -m ""= this will only commit the files that were already being tracked. no new files. ** How do you remove a file from git? precisely what does the command for this do? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763628836346 :ANKI_NOTE_HASH: ecd80c4a7d6b783d107bc5b06247f949 :END: you must remove the file from the tracked files (staging area) and then commit. =git rm= does this and also deletes the file from the working directory (so it's not "unstaged" later) ** When should you do the =-f= option for =git rm=? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763628836347 :ANKI_NOTE_HASH: 89c94cc39ef9a572514866f1b23f156e :END: if you modified the file or added it to the staging area. it's a safety feature to prevent removal of files that aren't in a snapshot. ** How to remove a file from staging area, but keep it in working directory? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763628836349 :ANKI_NOTE_HASH: 66128ddb9039252191dca62b72444176 :END: =git rm --cached = ** What order does =git log= show commits in? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763628836350 :ANKI_NOTE_HASH: 58efafd51682353403385c4b352cbdde :END: reverse chronological order -- most recent commits first. ** What does =git log -p -2= do? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763628836351 :ANKI_NOTE_HASH: 5fd9661174f222408c9245e1e77e10b9 :END: shows only last 2 commits with diff (or patch) details ** What do =git log --stat= and =git log --pretty= do? what values can pretty take? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763628836353 :ANKI_NOTE_HASH: 0333be11a07f37aaff67a1b46dbcf61c :END: =--stat= prints a list of modified files below each entry. how many such files, and how many lines were changed. =--pretty= has options: oneline, short, full, fuller, format: _____, etc. ** What does =git log -n= do where =n= is integral? How can you get commits made in the last 2 weeks? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763628836354 :ANKI_NOTE_HASH: 2551d8dee71897551c1d06be7ac91aaf :END: shows last 2 commits. =git log --since=2.weeks= also, =--until= is useful too. dates can be ="2008-01-15"= or even relative: "2 years 1 day 3 minutes ago" ** What =git log= flag is commonly referred to as the pick axe? What does this pickaxe do? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763628836355 :ANKI_NOTE_HASH: 05fe0e37ca10b822cba539042f3da68b :END: =git log -s = shows only those commits that changed the number of occurrences of =function_name= ** How can you filter in =git log= based on path? where in the command should this filter go? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763628836357 :ANKI_NOTE_HASH: 48d2aa1ebffedf6feb8cb610495c731d :END: at the very end, separated by =--= to segregate from the other options: =git log -- path/to/file= ** What flag allows you to declutter the log history from merge commits when using =git log=? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763628836358 :ANKI_NOTE_HASH: 2e3e98571aee63bd907751684725ba19 :END: =--no-merges= ** How can you fix a commit message / add an extra file to your commit (that hasn't been pushed yet)? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763628836360 :ANKI_NOTE_HASH: 90bba40ca18ef4a3b6cac78fc4b45d6f :END: =git commit --amend= note that you get a new hash, and the old commit never exists in the history. ** What does =git checkout -- = do? Are there perils? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763628836361 :ANKI_NOTE_HASH: b26216c437596d6cdd6c339354741afb :END: Yes, perils - you can lose work! It deletes changes and brings the file back to the last staged or committed version. ** Which 2 commands does =git restore= replace? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763628836362 :ANKI_NOTE_HASH: b60ef63694a569a435061ebe34a1972a :END: =git reset HEAD = and =git checkout -- = ** Which 2 commands does =git reset= replace? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763628836362 :ANKI_NOTE_HASH: 5e371e5af54f74f68a8eace4d564c741 :END: =git reset HEAD = and =git checkout -- = ** What is the command to add a new remote with shortname and URL? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763628836363 :ANKI_NOTE_HASH: 0ba4a348e644eed0ac17d91821da0005 :END: =git remote add = ** What does =git fetch = do? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763628836365 :ANKI_NOTE_HASH: 10def1f4fb4c5f1d2af5167c69be0a25 :END: it just downloads the data from whichever remote is the argument, and places it in the =.git= folder. no merging occurs. ** What does =git reset HEAD = do? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763628836366 :ANKI_NOTE_HASH: 39482870da5e41488ba2bbfc4ae23853 :END: It resets the file in the index to match =HEAD= (unstages it) while leaving the working directory version unchanged. ** How to see the URLs of *all* the remotes? What about a single remote? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763628836367 :ANKI_NOTE_HASH: 0cd9bd4c191243ba47ca64d91acc3c85 :END: =git remote -v= OR for more info on a single remote: =git remote show origin= ** How can you list tags? How can you (optionally filter them)? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763628836368 :ANKI_NOTE_HASH: 9855dd0a51ca63eb4a209be73082b65f :END: =git tag= with optional =-l= that respects globs =-l ""= ** What are the 2 types of tags? What do they do? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763628836369 :ANKI_NOTE_HASH: 6bf2e4fcb0e8d59e4bf4c2c1977598fb :END: lightweight: pointer to a specific commit annotated: full objects. checksummed; contain metadata: tagger name, email, date, message. ** How do you push tags? how can you delete them? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763628836372 :ANKI_NOTE_HASH: 2cea61a7495e3c3aa455c27d7b91f791 :END: =git push = or for lots: =git push --tags= delete: =git tag -d = (which does so locally) followed by =git push --delete = ** How can you create an annotated tag with message? how can you tag an old commit? how do you see tag data? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763628836371 :ANKI_NOTE_HASH: d855c3e5ae9bd88dc24b518a86a1aa41 :END: =git tag -a -m ""= =git tag -a = =git show = ** When is *rebasing* a bad idea? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763944597353 :ANKI_NOTE_HASH: 07273ec7813a2f97e47561d13f6db3e1 :END: when other people have based work on your commits. do *not* rebase those. ** How can you rebase =server= branch onto =master= without checking out =server= first? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763944597366 :ANKI_NOTE_HASH: 50b8b4174054554b9423ef130555a87c :END: =git rebase master server= "replay the commits *onto* master *from* server branch" ** What does =git rebase master= do? Assuming you're on the =experiment= branch? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_PREPEND_HEADING: t :ANKI_NOTE_ID: 1763944597389 :ANKI_NOTE_HASH: 1eea6ce160d9c0498af86e759860370f :END: [[file:~/Documents/new-site/static/doc/org/flashcards/img/rebase1.png]] *** Back goes to common ancestor; gets diff of every commit -- saves them into a temp file; resets =experiment= branch to same commit as =master=. applies each patch. you will then need to fast-forward by checking out =master= and merging =experiment= into it. [[file:~/Documents/new-site/static/doc/org/flashcards/img/rebase2.png]] [[file:~/Documents/new-site/static/doc/org/flashcards/img/rebase3.png]] ** What are the commands for a basic rebase? How are they different to a merge? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763947431084 :ANKI_NOTE_HASH: 828cfd09d2986d98c3d49382b94bc8e0 :END: rebase: =git checkout experiment= =git rebase master= "go to experiment branch, apply patches to master" merge: =git checkout master= =git merge experiment= "merge changes *into* current branch" ** What does rebasing do? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763947431105 :ANKI_NOTE_HASH: 7d7f51c750edd613b32750981e1d3189 :END: takes all the changes committed on one branch and replays them on another branch [[file:~/Documents/new-site/static/doc/org/flashcards/img/rebase2.png]] ** What is a small gotcha vis-a-vis the =git branch -vv= command and the information it returns? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763947431113 :ANKI_NOTE_HASH: b6fb564e8a8ff0658db568044f634e2c :END: it's telling you information about what we have cached from the last =fetch=. we are better off running =git fetch --all; git branch -vv= ** What does the =-vv= flag do to =git branch=? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763947431119 :ANKI_NOTE_HASH: 73d646fba07ea6da317a177c76ff4dd8 :END: shows what tracking branches have been set-up. lists out _local_ branches with more information; what each branch is tracking and if the local branch is ahead, behind or both. ** What is =@{u}= short for? What is an alternative short-form for this? What does =git merge @{u}= do? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763947431127 :ANKI_NOTE_HASH: fd9f99e02eec69a53c5b28ba5cdb4df5 :END: short for the upstream url. hence =@{upstream}= is another short-form. =git merge @{u}= merges the current branches' upstream into the current branch. ** If you already have a local branch and want to set it to a remote branch you just pulled down, or want to change the upstream branch you're tracking, the command is {{c1:: =git branch -u origin/=}} :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Cloze :ANKI_NOTE_ID: 1763947431139 :ANKI_NOTE_HASH: 1058772d1e28bb143fae90e6e5f744fb :END: ** What is =git checkout serverfix= an alias for, where you don't have the remote serverfix branch? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763947431145 :ANKI_NOTE_HASH: 48c99d3cc302010e2209b91b5a39e89f :END: =git checkout --track origin/serverfix= which itself is shorthand for =git checkout -b serverfix origin/serverfix= ** When you =git fetch= from a remote (=git fetch origin=), does that give you editable copies of the new branches? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763947431152 :ANKI_NOTE_HASH: b09b0eeb4c406a70477987529b54d24e :END: no, only unmodifiable pointers. you need to run =git merge origin/= which pulls in the changes into your _current_ branch. to make a new branch, use =git checkout -b serverfix origin/serverfix= ** How to push a branch up to a particular remote? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763947431157 :ANKI_NOTE_HASH: 36fc2eded0dac046119bdd966f59655e :END: =git push -u = This pushes the local branch to the given remote and sets its upstream, so that later you can just run =git push= on that branch. Creating a branch does *not* automatically push it; you must push it at least once as above. ** How to pull changes down from a certain remote? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763947431162 :ANKI_NOTE_HASH: 14bf9b7bc0f88576713d7939636e7a06 :END: =git fetch = ** How can we get a full list of remote references? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763947431165 :ANKI_NOTE_HASH: f92629206421909bac417e957910f688 :END: =git ls-remote = OR =git remote show = ** How do you rename a branch? Are there perils? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763947431173 :ANKI_NOTE_HASH: 1dd4bcbadef6fc6cd9558506aa911929 :END: =git branch -m = (rename branch locally) =git push -u origin = (push new branch name + set upstream) =git push origin --delete = (delete old branch from the remote) Perils: if others are using the old branch name (locally or tracking =origin/=), renaming/deleting it will break their setup until they rename or re-point their branches. ** What does =git branch --no-merged master= do? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763947431178 :ANKI_NOTE_HASH: cdad262d3cfb08cea1f90f9786b9f05d :END: shows you which branches have not been merged into master. You can give the final argument to see info on a branch you don't have checked out. ** What do the =--merged= and =--no-merged= options do on =git branch=? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763947431182 :ANKI_NOTE_HASH: 7b7b90f858d9a2d1d00f294071c3ecb7 :END: shows you which branches are already merged into the branch you're on. =--no-merged= shows the branches that have work that you have not merged in. ** What happens when you run =git branch= with no arguments? What about if you add =-v=? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763947431189 :ANKI_NOTE_HASH: b6f5ab55b320dec926865f0dd91d0a9b :END: naked is a simple listing. #+BEGIN_SRC bash git branch iss53 ,* master testing #+END_SRC note that =*= tells you what is currently checked out! (i.e. where the HEAD points) =-v= also shows the last commit on each branch: #+BEGIN_SRC bash $ git branch -v iss53 93b412c Fix javascript issue ,* master 7a98805 Merge branch 'iss53' testing 782fd34 Add scott to the author list in the readme #+END_SRC ** How can you solve merge-conflicts? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763949559427 :ANKI_NOTE_HASH: a39dbbb7746c2ab2a30172761176d024 :END: edit the files and choose the correct code. =git add= and =git commit= (staging the file marks it as resolved). you could also use =git mergetool= ** What happens when you do a =git merge= and the commit of the branch you're on is not a _direct_ ancestor of the branch you're merging in? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763949559435 :ANKI_NOTE_HASH: 16b6937e265f7df615efed2653183766 :END: simple three-way merge. uses the two snapshots pointed to by the branch tips and the common ancestor of the two. [[file:~/Documents/new-site/static/doc/org/flashcards/img/three-way-merge.png]] [[file:~/Documents/new-site/static/doc/org/flashcards/img/merge-commit.png]] ** How to merge =hotfix= branch into =main=? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763949559440 :ANKI_NOTE_HASH: 077baa79e51e52225a4d3813412a917e :END: =git checkout main= =git merge hotfix= note if you can fast-forward then you should delete the hotfix branch after merging: =git branch -d hotfix= ** What is "fast-forward"? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763949559461 :ANKI_NOTE_HASH: 9ad4b84bbb0dbca0c40a8c29bff5adb2 :END: When the merge has no divergent work to merge together it just moves the branch pointer forward [[file:~/Documents/new-site/static/doc/org/flashcards/img/rebase2.png]] [[file:~/Documents/new-site/static/doc/org/flashcards/img/rebase3.png]] ** How can you create a new branch and switch to it in the same command? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763949559466 :ANKI_NOTE_HASH: 4757e562678a815db8eada9b9b2ac182 :END: =git checkout -b = alternatively you can now use =git switch= with =--create= / =-c= for a new branch. note =git switch -= changes to the last branch. [[file:~/Documents/new-site/static/doc/org/flashcards/img/change-head.png]] ** Is it expensive to create and delete branches? Explain. :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763949559473 :ANKI_NOTE_HASH: cca2e823ec471bad9a5c59aef42ee671 :END: No, the pointers are just simple text files with the 40 character SHA1-hash checksums of the commit it points to. 41 bytes cost (+ newline) ** Which branches does =git log= show branches for? How can you modify this behaviour? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763949559497 :ANKI_NOTE_HASH: 81519d88d64e9a8a280808a6fbe1f11d :END: =git log = shows logs for an arbitrary branch =git log --all= shows for all branches but by default, it's whatever =HEAD= is pointing to. ** What is the command to switch an existing branch? How can you create a _new_ branch? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763949559503 :ANKI_NOTE_HASH: 41eb4c61950153f3bcc51c16d0ee8134 :END: =git checkout = =git branch = [[file:~/Documents/new-site/static/doc/org/flashcards/img/new-branch.png]] ** What command can we use to see where the branch pointers are pointing? i.e. HEAD :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763949559507 :ANKI_NOTE_HASH: b14016745464fca69f929cc44564ee45 :END: =git log --oneline --decorate= [[file:~/Documents/new-site/static/doc/org/flashcards/img/head-branch.png]] ** How does Git know what branch you're on? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763949559512 :ANKI_NOTE_HASH: 85a578b5b4b42379599d94db875eda2c :END: Keeps a special pointer called =HEAD= that is a pointer to the local branch [[file:~/Documents/new-site/static/doc/org/flashcards/img/head-branch.png]] ** How many pointers are in a commit object? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763949559518 :ANKI_NOTE_HASH: e1249dbba31f8c987e1978131b44d9a0 :END: - 0 for the initial commit (no parents) - 1 for regular commits - multiple (2?) for merge commits [[file:~/Documents/new-site/static/doc/org/flashcards/img/commit-parents.png]] ** What happens when you make a commit? What does Git store? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763949559522 :ANKI_NOTE_HASH: b931e85826654bf2edb3d167a3664e8f :END: stores a commit object with a pointer to the _snapshot_. also contains metadata + pointer/s to directly previous commits. [[file:~/Documents/new-site/static/doc/org/flashcards/img/commit-tree.png]] ** A branch in Git is simply a lightweight, movable {{c1::pointer}} to a commit. :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Cloze :ANKI_NOTE_ID: 1763949559529 :ANKI_NOTE_HASH: 1d38f44792df6d7259c2e5ba1a21cc8c :END: ** When does a file get a checksum? What does this imply has happened? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763949559535 :ANKI_NOTE_HASH: 456595f0714b0a0910944b4ace5b4462 :END: when the file is _staged_. implies a version of the file has been stored. (called blobs) # local variables: # eval: (anki-editor-mode +1) # end: ** What does =git diff --check= do? :noexport: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1764374181591 :ANKI_NOTE_HASH: d08e0bde0957c183bb582cbe0abec18f :END: identifies possible whitespace errors and lists them. ** Why should you write =git commit= messages in the imperative form? What does imperative form mean? :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1764374404370 :ANKI_NOTE_HASH: 6e137e57311af202ee386141f10d8bc4 :END: Write "Fix bug", not "Fixes bug" or "Fixed bug". The convention matches with commit messages generated by commands like =git merge= and =git revert=. ** How can you condense =git commit -a -m ""=? Is this true for all flags? :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1764374404374 :ANKI_NOTE_HASH: e191969c3ee9de20db61ffa3cadfcf47 :END: =git commit -am ""= not sure, will check. ** What does the three-dots syntax do? =git log --no-merges issue54...origin/master= :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1764374181611 :ANKI_NOTE_HASH: be60e9cda66d239bd074f2bb3ebae426 :END: The three-dots range =A...B= is the *symmetric difference* between the two branches. =git log --no-merges issue54...origin/master= shows commits that are reachable from either =issue54= or =origin/master=, but **not** from both — i.e. commits that are unique to one side or the other. (You can add =--left-right= to see which side each commit comes from.) ** What is the =-u= flag short for? =git push -u origin featureB:featureBee= :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1764374181615 :ANKI_NOTE_HASH: c1c210f533c7c107b84e6c7875387f56 :END: =-u= is short for =--set-upstream=. In: =git push -u origin featureB:featureBee= - =origin= is the remote. - =featureB:featureBee= uses the =:= syntax: - =featureB= is the **local** branch. - =featureBee= is the **remote** branch name on =origin=. The =-u / --set-upstream= flag makes the local branch =featureB= track =origin/featureBee=, so later you can just run =git push= or =git pull= with no extra arguments. ** What does =git merge --squash featureB= do? :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1764374181618 :ANKI_NOTE_HASH: 0a3d3d6d6fc6b4707ed07613d20c5b45 :END: todo... ** What does =git am= do? :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1764374181622 :ANKI_NOTE_HASH: dee67b0789bd83fe0c81524dcac60f9b :END: " _a_ pplies a series of patches from a _m_ ailbox" reads on mbox file, but can also accept a =.patch= file. ** What does =git log --pretty =fuller -1= do? :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1764374181625 :ANKI_NOTE_HASH: 9661849e437bccedfb50b5ed205577bd :END: shows last commit with fuller formatting. ** What does the =--not= option do here: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_PREPEND_HEADING: t :ANKI_NOTE_ID: 1764374181633 :ANKI_NOTE_HASH: 212a9edbdd5c2ee5029fcb3a43a9d48f :END: =git log --not master= *** Back excludes commits on the master branch. synonymous to =git log master...branch= ** What option can pass to =git log= to get the diff introduced by each commit? :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1764374181636 :ANKI_NOTE_HASH: e8d0b981fe1126e4d14c861d0cd58366 :END: =-p= ** How to do a diff between the last commit of the branch you're on and its common ancestor with another branch? :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1764374181639 :ANKI_NOTE_HASH: d6eaf87d1c148d85c218fece246a8f9d :END: On your feature branch, to see **what this branch has introduced since it forked from master**: =git diff master...= This uses the three-dots syntax: - In general, =git diff A...B= means: diff between =merge-base(A, B)= and =B= (changes **on B** since the common ancestor). - So =git diff master...= (or =git diff master...HEAD=) shows commits that are on your current branch but not on =master=, ignoring changes that only =master= has. (You can also write =git diff master...branch= if you want to compare explicitly to =branch=.) ** How to explicitly find the common ancestor of two branches =contrib= and =master=? :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1764374181642 :ANKI_NOTE_HASH: 69657ff221b2ce713276bde14ede9014 :END: =git merge-base contrib master= ** What is cherry-picking? What does the usage look like? :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1764374181645 :ANKI_NOTE_HASH: a92526c44b8d54eceb8b58d90ea9bfd6 :END: it is like a rebase, but for a single commit. =git cherry-pick = (cherry picks that commit into current branch) ** What does =git describe = do? :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1764374181648 :ANKI_NOTE_HASH: 3ac5059b0d8097eb289973d7459632b9 :END: Gives a human-readable string to describe a commit. ** What does =git shortlog --no-merges master --not v1.0.1= do? :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1764374181651 :ANKI_NOTE_HASH: 7dc627d5f67f949082b08da0973f7e1b :END: gives a short log of all the changes since the last release of v1.0.1 ** How to clone a repository? How to specify a path to clone into? :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1764374181654 :ANKI_NOTE_HASH: 1f8209eabd1434c351b6b26e42086f99 :END: =git clone = ** What is a bare repository? How can you create one? :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1764374181657 :ANKI_NOTE_HASH: b8c5a53d30117634e9e6cfbaf74449e0 :END: a Git repository with no working directory. =git clone --bare = =git init --bare .git= the =.git= part is convention for bare repositories. ** What does ssh-keygen do? What does adding the =-o= flag do? :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1764374181660 :ANKI_NOTE_HASH: 755831c9f4c4372a32dacb47efbde9ad :END: Generates a public and (corresponding) private key. =-o= saves the private key in a format more resistant to brute-force attacks. (use this option if setting a password) ** What are some pros and cons of setting up Git on your own webserver? :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1764374181664 :ANKI_NOTE_HASH: 3f586d9ffcb8a17752ed3ef4a8877b43 :END: pros: - lots of control - run everything from within your own firewall - some organisations might not allow code on another server cons: - time to set-up - maintainence efforts ** What are the 4 distinct protocols Git can use to transfer data? :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1764374181667 :ANKI_NOTE_HASH: 372a52633977d64f36d3e6831e42fff5 :END: local, http, secure shell (ssh), git. ** How do you check the open issues in a repository with =gh=? :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1764374181669 :ANKI_NOTE_HASH: 1db26de094bde066f8abed1d5d1f1f51 :END: =gh issue list --state open= ** How do you see the descriptions of a particular Github issue using =gh=? :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1764374181673 :ANKI_NOTE_HASH: b9a45104b512b342ba65b7f22d4cab6c :END: =gh issue view = ** Is Github a part of Git? :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1764374181676 :ANKI_NOTE_HASH: 8ec46c590c82fde7c01006bedbd6ff4b :END: No, it is a _Git host_. A place where some functionalities become simpler. ** How does _Github_ map commits to your user? :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1764374181681 :ANKI_NOTE_HASH: d98f397edde076f9f27b82241cf84145 :END: by email address ** Do forks exist as part of Git or Github? How about pull-requests? :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1764374181684 :ANKI_NOTE_HASH: b2d5c7c3d9ba4b1ecb4f0d6617151870 :END: todo ** Is it true that often pull requests are created at the beginning of a project? If so, why? :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1764374181688 :ANKI_NOTE_HASH: c957712160431e258f41ba818375782b :END: True. Because you can keep pushing to the topic branch even after the pull request is opened. ** How can you update a pull request with new code? :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1764374181691 :ANKI_NOTE_HASH: ba916f109eddf9e67db3a85e28b054c3 :END: Commit to the topic branch and push. The pull request gets updated automatically. ** How can you solve "Pull request does not merge cleanly"? :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_PREPEND_HEADING: t :ANKI_NOTE_ID: 1764374181694 :ANKI_NOTE_HASH: c8d9ef4ad0794b5e8946da018e13d53d :END: [[file:img/pull-request-not-merge-cleanly.png]] *** Back two main options: 1. rebase your branch on top of whatever the target branch is 2. you can merge the target branch into your branch (preferred) ** In Github, all issues and pull requests are assigned {{c1::numbers}} and they are {{c1::unique}} within the project :PROPERTIES: :ANKI_NOTE_TYPE: Cloze :ANKI_NOTE_ID: 1764374181699 :ANKI_NOTE_HASH: 8c0bd989458f0fc69b33a5c7ec9fe284 :END: ** How can you reference issues/pull requests from comments? What are the three syntaxes? :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1764374181702 :ANKI_NOTE_HASH: c336c7d311e33f11574af439c727479e :END: - same scope (i.e. same fork): =#= - another fork: =username #= - different repo: =username/repo#= ** What happens at the bottom of an issue or pull request if someone links to it with the =#= syntax? :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1764374181704 :ANKI_NOTE_HASH: a7abe43deca0c21076e1eb38fd7956c1 :END: Github create a 'trackback' event ** In addition to linking to issue numbers in Github, you can also reference a specific {{c1::commit}} by the {{c1::full 40 character SHA-1 hash}}. :PROPERTIES: :ANKI_NOTE_TYPE: Cloze :ANKI_NOTE_ID: 1764374181708 :ANKI_NOTE_HASH: 276f04e52bf0fed102b8051b1032dbc6 :END: ** What is a really cool aspect of the checkbox syntax in Github flavoured markdown? :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_PREPEND_HEADING: t :ANKI_NOTE_ID: 1764374181710 :ANKI_NOTE_HASH: 76eacdf75c14eddf413cd39fed769ceb :END: #+BEGIN_SRC markdown - [X] write the code - [ ] write all the tests #+END_SRC *** Back simply clicking the checkbox updates the comment -- there is no need to manually edit the file! ** How can task lists be used in Issues and Pull requests on pages that list these out? :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1764374181713 :ANKI_NOTE_HASH: 550ca65fdabc569f0646879dbd9f174b :END: A little icon with their progress appears beside the headings. ** How to write emojis in Github? :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1764374181716 :ANKI_NOTE_HASH: 074018f8c80f78baa68acad95878440c :END: #+BEGIN_SRC markdown I :eyes: that :bug: and I :cold_sweat:. :trophy: for :microscope: it. :+1: and :sparkles: on this :ship:, it's :fire::poop:! :clap::tada::panda_face: #+END_SRC ** Pull requests can either come from a {{c1::branch}} in a {{c1::fork}} of your repository or they can come from {{c1::another branch in the same repository}}. :PROPERTIES: :ANKI_NOTE_TYPE: Cloze :ANKI_NOTE_ID: 1764374181719 :ANKI_NOTE_HASH: 2c6407bc0fae2e9b5877dfdcff698dc7 :END: ** What is the command to merge in a remote branch without having to add a remote? :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1764374181722 :ANKI_NOTE_HASH: a73e7c88ec18820a070861faa5e1ee1f :END: =git pull patch-1= ** Technically speaking, what does this do? :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_PREPEND_HEADING: t :ANKI_NOTE_ID: 1764374181725 :ANKI_NOTE_HASH: 6ff81f6a089a294088f979da31831608 :END: #+BEGIN_SRC bash $ curl https://github.com/tonychacon/fade/pull/1.patch | git am #+END_SRC *** Back merges in the pull request. ** Is =ls-remote= a plumbing command or porcelain command? What happens if you run it on a repository? :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1764374181727 :ANKI_NOTE_HASH: 487e6d823196bf6c26844155db9b68fc :END: plumbing. gives a list of all the branches and tags and other references in the repo. ** What does the =CONTRIBUTING= file do on Github? :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1764374181731 :ANKI_NOTE_HASH: 33a98e8c44ab2e0203b6a74630022517 :END: It shows contributors the rendered version of the file when they start opening a pull request. ** What is this an example of? :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_PREPEND_HEADING: t :ANKI_NOTE_ID: 1764374181734 :ANKI_NOTE_HASH: cf11dca307989142ac3eddbaddb692fe :END: [[file:img/audit-log.png]] What kind of entities have this functionality in Github? *** Back Audit log. Github organisations. ** What are the 2 main systems for scripting Github? :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1764374181873 :ANKI_NOTE_HASH: 3a8f86dd5340e3494af81b6c4caba351 :END: 1. Hooks and Services 2. API [[file:img/service-hooks.png]] ** What are the rate limits to Github when authenticated vs. when not? :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1764374181877 :ANKI_NOTE_HASH: 87aca2ee145a40184a76b1a7cc484cf6 :END: 5,000 vs. 60. ** Is Curl + HTTP requests the best way to interface with the Github API? :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1764374181881 :ANKI_NOTE_HASH: 0a4ffa10a587fefa63776e03d2cdc191 :END: There is never a "best way", but other languages like Go, .NET, Objective-C and Ruby *do* have more idomatic frameworks for the API.