* Git :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: cb33a726caa5c0696964ade5358af1cd :END: 1. Modified (changed in your working directory) 2. Staged (in the index, ready for commit) 3. Committed (saved in the repository / HEAD history) ** 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: 6af79d43c44866a64921fc73c9d95ca8 :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: 226b6e68de65ffe6c3c5cad9b96a11a1 :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: a1915fdee283a0b12227469584207b77 :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: a444b0df874115f6fe32f84750d6156d :END: =git log -S= (the “pickaxe”) shows commits where the number of occurrences of changes (added/removed). (Note: =git log -s= just suppresses diff output.) ** 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: 9a2c870609a9b0a558dd5a8cab2bfad5 :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: 18bb5e33b6f6b2456eacb38dd29f64f7 :END: Use =git commit --amend=. - To fix the message only: =git commit --amend -m "new message"= (or run without =-m= to edit in your editor) - To add a forgotten file: =git add = then =git commit --amend --no-edit= Amending rewrites the last commit: it creates a *new* commit with a new hash (the old commit becomes unreachable unless referenced). Avoid amending if the commit has already been pushed/shared (or you’ll need a force push). ** What does =git checkout -- = do? Are there perils? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763628836361 :ANKI_NOTE_HASH: 2243796a199829d945d8883476c26d15 :END: It discards *working-tree* changes to by replacing it with the version from the index (staging area). If the file is not staged, that effectively means “restore from =HEAD=​”. Perils: - It can permanently lose local edits in your working directory (not just “unstage”). - It does *not* create a commit or safety net. Safer / modern equivalents: - =git restore = (restore working tree from index) - =git restore --source=HEAD = (force restore from last commit) ** 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: cb8e347fbd44a8dad585abb334d53a43 :END: (For the “unstage” use-case) =git reset= replaces: =git reset HEAD = Because =git reset = defaults to =HEAD=, so: =git reset = is the shorter equivalent. Note: =git checkout -- = is a *different* operation (discard working-tree changes) and is now commonly written as: =git restore = ** 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: 1f38ce911b02ee8728210376d48874d2 :END: [[file: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:img/rebase2.png]] [[file: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: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:img/three-way-merge.png]] [[file: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:img/rebase2.png]] [[file: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: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: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: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: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: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: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) ** 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? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1764374404370 :ANKI_NOTE_HASH: 242a3d89c4b4282096a443315512eb19 :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? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1764374404374 :ANKI_NOTE_HASH: b19664b817918eda8325995f1907ae6f :END: Yes: you can combine short flags, so: =git commit -am "msg"= is the same as: =git commit -a -m "msg"= But **no**, this is *not* true for all flags. Only **single-letter** short options can be grouped like this, and only when they don’t require their own attached value. Examples: - OK: =-am= (equivalent to =-a -m=; =-m= takes its message as the next argument) - NOT like this: you generally can’t combine long options (e.g. =--amend=) or assume every short flag combination is valid. ** What does the three-dots syntax do? =git log --no-merges issue54...origin/master= :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1764374181611 :ANKI_NOTE_HASH: d76706366b28a719bd760077e831c342 :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= :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1764374181615 :ANKI_NOTE_HASH: 587cfc52da66c0a233c9f14010e7aad8 :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? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1764374181618 :ANKI_NOTE_HASH: 2da77008370862699ad2468640e3279c :END: It takes all the changes introduced by branch =featureB= (since the merge-base with your current branch) and applies them to your working tree/index as *one combined* change, without creating a merge commit and without recording the branch history. After running it: - the changes are staged (like a big “combined” diff) - you still need to run =git commit= to create the single squashed commit - it does *not* mark =featureB= as “merged” in Git history (a later normal merge may try to reapply commits). ** What does =git am= do? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1764374181622 :ANKI_NOTE_HASH: 86df72b9316111848d1751202fefe7f6 :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? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1764374181625 :ANKI_NOTE_HASH: 732155a4aa41791f185a555450de091b :END: shows last commit with fuller formatting. ** What does the =--not= option do here: :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_PREPEND_HEADING: t :ANKI_NOTE_ID: 1764374181633 :ANKI_NOTE_HASH: 6cb2da5c2ac595d85290233f40a6fc54 :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? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1764374181636 :ANKI_NOTE_HASH: 159585613a0c05d0a7da3cbe5c469b78 :END: =-p= ** How to do a diff between the last commit of the branch you're on and its common ancestor with another branch? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1764374181639 :ANKI_NOTE_HASH: 21299c2777556ade6f576d6ee31a9b1d :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=? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1764374181642 :ANKI_NOTE_HASH: 42d6322909ed26b3fd47323a686c6316 :END: =git merge-base contrib master= ** What is cherry-picking? What does the usage look like? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1764374181645 :ANKI_NOTE_HASH: fc63f4a317ae8ea2c9ff7a824e1a8a9a :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? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1764374181648 :ANKI_NOTE_HASH: 09d359954925fe52230765f315cce4fb :END: Gives a human-readable string to describe a commit. ** What does =git shortlog --no-merges master --not v1.0.1= do? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1764374181651 :ANKI_NOTE_HASH: 531ff80d141d82c765cc302b62447914 :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? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1764374181654 :ANKI_NOTE_HASH: ad6ff4cf1c6714564fae12fdc98c4f83 :END: =git clone = ** What is a bare repository? How can you create one? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1764374181657 :ANKI_NOTE_HASH: 219ad266da3b7ae820173db9c6b1d286 :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? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1764374181660 :ANKI_NOTE_HASH: 3b7b8286531822843d9ac431a8582394 :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? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1764374181664 :ANKI_NOTE_HASH: 57eeb47f38a48331304915170ed0e077 :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? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1764374181667 :ANKI_NOTE_HASH: 4abe3881e79db76f71d135ccae55eb2c :END: local, http, secure shell (ssh), git. ** How do you check the open issues in a repository with =gh=? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1764374181669 :ANKI_NOTE_HASH: 9053383b74c359962d58b3625b94726c :END: =gh issue list --state open= ** How do you see the descriptions of a particular Github issue using =gh=? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1764374181673 :ANKI_NOTE_HASH: d237641ae38f9978874e91a91c81f2b1 :END: =gh issue view = ** Is Github a part of Git? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1764374181676 :ANKI_NOTE_HASH: 510318851f1f58ad7562f0fab3e96c37 :END: No, it is a _Git host_. A place where some functionalities become simpler. ** How does _Github_ map commits to your user? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1764374181681 :ANKI_NOTE_HASH: 63548591176146091249ba4aea97fb80 :END: by email address ** Do forks exist as part of Git or Github? How about pull-requests? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1764374181684 :ANKI_NOTE_HASH: 885f1abbc238f22e6d5300c28464cc45 :END: Forks and pull requests are not core Git features; they are hosting-platform features (e.g., GitHub/GitLab/Bitbucket). In Git itself, you only have repositories and remotes; a “fork” is just another repo you can add as a remote, and a “pull request” is a workflow built on Git commits/branches plus platform review + merge tooling. ** Is it true that often pull requests are created at the beginning of a project? If so, why? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1764374181688 :ANKI_NOTE_HASH: ccc243310572212fe1c5a66a03ff7cbd :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? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1764374181691 :ANKI_NOTE_HASH: 175fc027ba2b99d91f00fb9eac96852a :END: Commit to the topic branch and push. The pull request gets updated automatically. ** How can you solve "Pull request does not merge cleanly"? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_PREPEND_HEADING: t :ANKI_NOTE_ID: 1764374181694 :ANKI_NOTE_HASH: 92121b5af7e9c6aab8f9cda4ba5ed87e :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 :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Cloze :ANKI_NOTE_ID: 1764374181699 :ANKI_NOTE_HASH: c225b5eba596b5e4709acaa63eb12384 :END: ** How can you reference issues/pull requests from comments? What are the three syntaxes? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1764374181702 :ANKI_NOTE_HASH: c991350529d3b0a138e07dbf6f8da5fa :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? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1764374181704 :ANKI_NOTE_HASH: c3b69eab66c2e30098b1d072fcd79f57 :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}}. :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Cloze :ANKI_NOTE_ID: 1764374181708 :ANKI_NOTE_HASH: d8fbac4906f84e87d38c1ccc43627171 :END: ** What is a really cool aspect of the checkbox syntax in Github flavoured markdown? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_PREPEND_HEADING: t :ANKI_NOTE_ID: 1764374181710 :ANKI_NOTE_HASH: 263d2cfe0e36bb851cac2f9b817a4ced :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? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1764374181713 :ANKI_NOTE_HASH: 677788ec4c0d92ca10036f9072ab146c :END: A little icon with their progress appears beside the headings. ** How to write emojis in Github? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1764374181716 :ANKI_NOTE_HASH: 5ab23f6b5dbb10164fd81af382b3e3a2 :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}}. :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Cloze :ANKI_NOTE_ID: 1764374181719 :ANKI_NOTE_HASH: 1c49e01feea8cf195d844bccac324fcf :END: ** What is the command to merge in a remote branch without having to add a remote? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1764374181722 :ANKI_NOTE_HASH: 70bfe2123d432e55b170978dcc572700 :END: =git pull patch-1= here =patch-1= is the branch. ** Technically speaking, what does this do? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_PREPEND_HEADING: t :ANKI_NOTE_ID: 1764374181725 :ANKI_NOTE_HASH: 3863d7edd1a6b7bd321fb34c181410fd :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? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1764374181727 :ANKI_NOTE_HASH: 4d21b4415c2396ae03076aae4d619f3a :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? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1764374181731 :ANKI_NOTE_HASH: 9815e953901ff117b29eb07197de253e :END: It shows contributors the rendered version of the file when they start opening a pull request. ** What is this an example of? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_PREPEND_HEADING: t :ANKI_NOTE_ID: 1764374181734 :ANKI_NOTE_HASH: e6f8a4705ba9eae100abfff96f1002c6 :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? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1764374181873 :ANKI_NOTE_HASH: 62b13c979861ad25b2216bdc6624d713 :END: 1. Hooks and Services 2. API [[file:img/service-hooks.png]] ** What are the rate limits to Github when authenticated vs. when not? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1764374181877 :ANKI_NOTE_HASH: bf047bd2bce0090e196453c3e6cdf982 :END: 5,000 vs. 60. ** Is Curl + HTTP requests the best way to interface with the Github API? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1764374181881 :ANKI_NOTE_HASH: 808fdeac185a58189cfa91ee1d66ac82 :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. ** What to do when you do a =git init= followed by a =git add -A= of many large files? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1764703958981 :ANKI_NOTE_HASH: cbe0916631c97d0d58d22f252707899f :END: =git rm -r --cached= (unstages everything) =git gc --prune=now= (deletes blobs) ** What does =git blame= do? :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1765015661784 :ANKI_NOTE_HASH: f61f5cb059f2cda7d69482505852e3e2 :END: for each line in a file, it shows the last commit that modified it: who made the change, when, and which commit it was. e.g. =git blame path/to/file.py= ** What does the syntax =git show commit:file= do? :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1765015661789 :ANKI_NOTE_HASH: 8a2b6247353e5e4798bafdefd8ec0cf7 :END: It shows the contents of =file= as it was in =commit= (or any commit-ish), without changing your working tree or HEAD. e.g. =git show HEAD~2:src/main.py= prints how =src/main.py= looked two commits ago. # local variables: # eval: (anki-editor-mode +1) # end: