* 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 cofiguration settings for a specific key? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1766998175394 :ANKI_NOTE_HASH: b920f4cacd96b50c0a62d1203df8a242 :END: =git config = ; where key can be something such as =user.name= or =user.email=, =core.editor=, etc. ** What command can you use to check the git configuration settings? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763628836324 :ANKI_NOTE_HASH: c764c321258f34cd2675c640197fe482 :END: =git config --list= ** 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: 54c1a4bf89f82aa3641024946e7bcd3f :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:git: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763628836361 :ANKI_NOTE_HASH: 8129b0dfb3946be2813834aa41b5d982 :END: *** Back It discards *working-tree* changes to by replacing it with the version from the *index* (staging area). *How it behaves:* - If file is staged: restores the staged version - If file is not staged: restores from =HEAD= (because index matches =HEAD=) *Perils:* - Permanently loses uncommitted local edits in your working directory - No safety net—changes are gone forever - Does *not* create a commit or backup *Safer modern equivalents:* - =git restore = (restore working tree from index) - =git restore --source=HEAD = (explicitly restore from last commit) - =git restore --staged = (unstage without discarding working changes) *Note:* =git checkout --= is deprecated in favour of =git restore= ** What's the difference between =git restore = and =git restore --staged =? :progit:git: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1766577683216 :ANKI_NOTE_HASH: bc91d00c327d61f4e24c33bf6f769cc5 :END: *** Back *=git restore =* - Discards working directory changes - Restores file from the index (staging area) - Leaves staging area unchanged - Use when: you want to undo edits but keep staged changes *=git restore --staged =* - Unstages the file (removes from index) - Leaves working directory unchanged - Your edits remain in the working tree - Use when: you staged something by mistake but want to keep your changes *Common workflow:* #+begin_example # Made changes and staged them git add file.txt # Oops, didn't mean to stage yet git restore --staged file.txt # unstage, keep changes # Actually, don't want these changes at all git restore file.txt # discard working changes #+end_example *Key insight:* One affects staging area, one affects working directory ** If you've staged changes to a file, what does =git checkout -- = restore: the staged version or the HEAD version? :progit:git: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1766577683218 :ANKI_NOTE_HASH: 382fb917ef775c64215c02defc2678a2 :END: *** Back The *staged version* (from the index). *Example scenario:* #+begin_example # Original file has "A" echo "B" > file.txt git add file.txt # Index now has "B" echo "C" > file.txt # Working tree now has "C" git checkout -- file.txt # Restores "B" (staged version) # NOT "A" (HEAD version) #+end_example *Key point:* =git checkout -- = always restores from the *index*, not directly from HEAD. *To restore from HEAD instead:* - =git checkout HEAD -- = - =git restore --source=HEAD = This is why it's important to know what's in your staging area! ** Which 2 commands does =git restore= (with different flags) replace? :progit:git: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763628836362 :ANKI_NOTE_HASH: b60ef63694a569a435061ebe34a1972a :ANKI_FAILURE_REASON: Note was not found: 1763628836362 :END: *** Back *=git restore =* replaces: - =git checkout -- = (discard working directory changes) *=git restore --staged =* replaces: - =git reset HEAD = (unstage file) *Why the change:* Git introduced =git restore= and =git switch= to split the overloaded functionality of =git checkout= into clearer, more focused commands. *Mnemonic:* - No flag = restore *working tree* - =--staged= flag = restore (remove from) *staging area* ** What's the modern replacement for =git reset HEAD = (unstaging)? :progit:git: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1766577683221 :ANKI_NOTE_HASH: 9613736f648d025138a6e0f154f9535f :END: *** Back =git restore --staged = *Why the change:* - More explicit and clear intent - =git reset= is overloaded (moves HEAD, unstages, discards changes depending on flags) - =git restore --staged= only does one thing: unstage *Shorthand equivalents:* =git reset = (HEAD is default) = =git reset HEAD = But both are now discouraged in favour of =git restore --staged=. ** 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: ed1bf48f2251f83b91c6411b69f7b653 :END: lightweight: pointer to a specific commit annotated: full objects. checksummed; contain metadata: tagger name, email, date, message. ** How can you delete tags? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1766997460198 :ANKI_NOTE_HASH: 90d73b4dd3c60beef4373033d92c0529 :END: first locally: =git tag -d = then on the upstream: =git push --delete = ** How do you push tags? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763628836372 :ANKI_NOTE_HASH: 7a373639de8b8264d223b44cd1ae05e0 :END: =git push = or for lots: =git push --tags= ** How can you create an annotated tag with message? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763628836371 :ANKI_NOTE_HASH: afa112b48843ddd104cfc60c3d217bee :END: =git tag -a -m ""= ** How can you tag an old commit? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1766576670400 :ANKI_NOTE_HASH: 4bdd5e7072768512ad5021baaff854f2 :END: =git tag -a = ** How do you see tag data? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1766576670405 :ANKI_NOTE_HASH: 04c7d40436c0c1339d293ded3c062e7c :END: =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: 170a4aaf12e9694d2198bad6df327849 :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: 9a3dfe5c9bd5a05f0d678b9818377e67 :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 do you download changes from a remote repository without merging them? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763947431162 :ANKI_NOTE_HASH: 53df91e7c73e08fa26895926eccba283 :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: 12c0ed16e9b686b4ac8619c38568d919 :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: 1be93aa2e9969275384b184a28709538 :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: 5017b34025807cce610286f854a50552 :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: 10c708d6b30fc6e5a2f6aa0dd394f99e :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: 8b02d89007e845dee7b2d3cd53ef9e97 :END: =git log --oneline --decorate= *Modern note:* =--decorate= is now on by default in most Git versions [[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: 287ece211b1b3ad4ab1195e1e17ee325 :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: 500d019be23234bbb3d5c4ee38e7ee99 :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: 04efa1cca460cc29d940acc9275ae3d6 :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: 9abedf0c7ea09d513df4caaedf3a03cc :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: 5ab8b61e5cefbcaa60ea10c43eb13454 :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: Cloze :ANKI_NOTE_ID: 1764374181702 :ANKI_NOTE_HASH: 3927764e938ecd88570f659944fb1b3b :ANKI_PREPEND_HEADING: t :END: *** Text How can you reference issues/pull requests from comments? What are the three syntaxes? - {{c1::same scope (i.e. same fork):}} ={{c4::#}}= - {{c2::another fork:}} ={{c3::username#}}= - {{c6::different repo:}} ={{c5::username/repo#}}= *** Back Extra ** 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: ** How can you pull and merge changes from someone's fork without adding it as a remote? :progit:git: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1764374181722 :ANKI_NOTE_HASH: 96aa4dfac25591b9db8bfa6fd013c38f :END: *** Back =git pull = *Example:* =git pull https://github.com/username/repo patch-1= *When to use this:* - One-off contributions you want to test/merge - Don't want to permanently add their fork as a remote - Quick way to fetch and merge someone else's branch *Compare to normal workflow:* #+begin_example # Normal way (if you'll collaborate repeatedly): git remote add contributor git pull contributor patch-1 # One-off way: git pull patch-1 #+end_example ** 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? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1765015661789 :ANKI_NOTE_HASH: 63150238f4b5d91e580fe6c5035996fd :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. ** What is the minimum number of characters required to (uniquely) refer to a SHA-1 Hash? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_PREPEND_HEADING: t :ANKI_NOTE_ID: 1766293156564 :ANKI_NOTE_HASH: 7ca5db2d56ecdb228f9d0efc5e5e399f :END: What is the other requirement? *** Back :progit: 4 chars minimum; uniqueness ** What is the difference between =git log --oneline= and =git log --abbrev-commit --pretty=oneline=? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1766293156565 :ANKI_NOTE_HASH: 2cbc455e371e2d8db15a6708a0c197d4 :END: They are the same. Note though, that =git log --pretty=oneline= does not abbreviate the commits. ** What does =git rev-parse topic1= do? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_PREPEND_HEADING: t :ANKI_NOTE_ID: 1766293156567 :ANKI_NOTE_HASH: b41aa4efdf6a6c53db76741cf6330589 :END: Where =rev-parse= is a plumbing command, and topic1 is a branch (pointer) *** Back :progit: Shows the SHA-1 hash of the commit that the branch is pointing to. ** Does a freshly cloned repo have a =reflog=? What does reflog stand for? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1766293156568 :ANKI_NOTE_HASH: e966470c28ab9a9b936e7d53cf1b2b27 :END: Nope -- it only records the current users actions. "Reference log" -- a log of where the =HEAD= and branch references have been (for the last few months) ** How to see reflog information in a =git log= call? What is the flag? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1766293156569 :ANKI_NOTE_HASH: ad5ab0f3df6673724b10f8b57518eddb :END: =-g= ** What does the =HEAD@{n}= syntax do? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_PREPEND_HEADING: t :ANKI_NOTE_ID: 1766293156570 :ANKI_NOTE_HASH: 518d51a39e0f5414c729d78ac7eac2e6 :END: What about =HEAD^n=? *** Back :progit: =HEAD@{n}= shows the $n\textup{th}$ previous place =HEAD= has been (contingent on reflog!) =HEAD^n= might bug on non-merge commits, because normal commits only have 1 parent. =^= is ancestor syntax ** What does =git show HEAD~3= do? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1766293156571 :ANKI_NOTE_HASH: 0f97eb6ae812021d3f58dec85a9921e5 :END: traverses the parent of =HEAD=, 3 times. i.e. grand-grand parent of =HEAD= (equivalent to =HEAD~~~= ** What does the double-dot syntax do? What is it useful for? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1766293156572 :ANKI_NOTE_HASH: de4f7e5e4884e996a8c7e739063c6ca5 :END: useful for isolating commit ranges? Asks Git to resolve a range of commits that are reachable from one commit but not from another. ** What does =git log master..experiment= do? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1766293156573 :ANKI_NOTE_HASH: 6b270d1ae1be29eecc8bd7ee436f8bdd :END: lists all commits reachable from =experiment= but not reachable from =master= ** What does =git log origin/master..HEAD= do? What is it useful for? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1766293156574 :ANKI_NOTE_HASH: 94e063b658c343b6a083f00af3f6682a :END: useful to see what you are about to push to a remote. (=origin/master= is the remote; recall the double-dot syntax) ** What does git infer when you leave off a branch name in the double-dot syntax? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_PREPEND_HEADING: t :ANKI_NOTE_ID: 1766293156575 :ANKI_NOTE_HASH: 12a420265b5d93506562b4a50c15ee6e :END: =git log origin=master..= *** Back :progit: infers =HEAD= works on either side. ** What happens when you use the =^= syntax _before_ a reference? What is this a synonym to? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1766293156577 :ANKI_NOTE_HASH: 7dd600fc2991e33f39db8d3eea1e164a :END: synonyms to =--not=, hence =git log refA..refB= =git log ^refA refB= =git log refB --not refA= ** What does the triple-dot syntax do? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1766293156578 :ANKI_NOTE_HASH: a992d37b4d56d1cf5d4436fe8688870a :END: specifies all the commits that are reachable by _either_ of the two references, but not by both. ** What does the =--left-right= flag do on git log? What syntax is it most useful with? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1766293156579 :ANKI_NOTE_HASH: 77bb959f2eb46e67900a72a1cbacaaa9 :END: gives angle brackets pointing at the reference the commit belongs to: #+BEGIN_SRC bash $ git log --left-right master...experiment < F < E > D > C #+END_SRC most useful with triple-dot syntax ** How can you add files in git interactively? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1766293156580 :ANKI_NOTE_HASH: 8253d6ba69c00001689da4c2795d0f19 :END: =git add -i= ** What does stashing do in Git? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1766293156581 :ANKI_NOTE_HASH: a0ea02b77ec766332167dc7bd3346928 :END: takes the dirty state of the working directory (modified tracked files and staged changes), and saves them on a _stack_ of unfinished changes that you can re-apply later. ** How do you see all the stashes? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1766293156582 :ANKI_NOTE_HASH: c17840295cadc9d3f0acde35ec4c8e54 :END: =git stash list= ** How do you create a stash? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1766293156583 :ANKI_NOTE_HASH: 0d1bdf08738edd738edb1d20d3bb9673 :END: =git stash= or =git stash push= ** How do you apply a stash? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1766293156584 :ANKI_NOTE_HASH: c9c799b596c692f1fd3f0704523b4482 :END: =git stash apply= ** Does =git stash apply= delete the stash from the stack? If not, how can we do so? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1766293156585 :ANKI_NOTE_HASH: b67b775ae423da0bc5cec083adb0d4c1 :END: It does not. It only applies the stash. =git stash drop = or =git stash pop= ** What does the =git clean= command do? What is the dry-run flag? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1766293156586 :ANKI_NOTE_HASH: 78483b8fe3a5dc1b323b8ef6530b14b2 :END: removes files that are not tracked. =--dry-run= ( or =-n=, which you can later swap for =-f= ) ** Does =git clean= remove =.gitignore=​'d files? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1766293156587 :ANKI_NOTE_HASH: 427fcfd4a3db548dd05dc81c46edd53d :END: Nope, but you can make it do so with =-x= ** What is the searching command that git ships with? Why is it superior to =sed=, =awk=, etc? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1766293156588 :ANKI_NOTE_HASH: 59313ab05818eee1ca5c7766c8b3db33 :END: =git grep= -- allows searching across branches! (and perhaps even through history) ** What are some useful flags for =git grep=? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1766293156589 :ANKI_NOTE_HASH: 63ae2b46f62db8121a269b82d3fee547 :END: =--count= =--line-numbers= (=-n=) =-p= (=--show-function=) ** What are the two ways in which we could want to change a Git commit? How can you solve each? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1766293156590 :ANKI_NOTE_HASH: 7530c0314792908d615f6ee8f38c8a77 :END: 1. change commit message - =git commit --amend= 2. change commit contents - make modifications - stage changes - =git commit --amend= ** What flag can you give to =git commit --amend= to skip the message altering? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_PREPEND_HEADING: t :ANKI_NOTE_ID: 1766293156591 :ANKI_NOTE_HASH: dd491ab28764a2931f4a13b6c54bdb20 :END: Note: this is for when you make tiny changes that do not warrant a new commit message *** Back :progit: =--no-edit= ** How do you modify a commit further back in the history? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1766293156592 :ANKI_NOTE_HASH: 5063091579b56a6f32d63ba6e612a64d :END: =git rebase -i HEAD~3= note: =HEAD~3= will be the commit that is the /parent of commit head - 2/ perils: rewrites last 3 commits ** How can you tak ea series of commits and squash them down into a single commit? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1766293156593 :ANKI_NOTE_HASH: cc97f604706023f24fd1f3606371848d :END: with the interactive rebasing tool. =git rebase -i = ** What are some of the things you can do with interactive rebasing? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1766293156594 :ANKI_NOTE_HASH: cff9547ba7437a16708cc69e6c9a19cc :END: - changing multiple commit messages - reordering commits - squashing commits - splitting commits - deleting commits ** What command should we use for rewriting git history on a larger number of commits in some scriptable way? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1766293156595 :ANKI_NOTE_HASH: 9dbfa81b7aca9b6df91a705edbc3ead7 :END: =filter-branch= ** How to remove a file named =passwords.txt= from the entire history? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1766293156596 :ANKI_NOTE_HASH: 44474e62e072d1ac6246485e077ea574 :END: =git filter-branch --tree-filter 'rm -f passwords.txt' HEAD= ** Git as a system manages and manipulates three trees in its normal operation: :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Cloze :ANKI_PREPEND_HEADING: t :ANKI_NOTE_ID: 1766291642376 :ANKI_NOTE_HASH: 32caf99e552067a34dea4c4287e6e74f :END: *** Text :progit: Git as a system manages and manipulates three trees in its normal operation: | Tree | Role | |---------------------------+-------------------------------------------| | {{c1::HEAD}} | {{c4::last commit snapshot, next parent}} | | {{c2::index}} | {{c5::proposed next commit snapshot}} | | {{c3::working directory}} | {{c6::sandbox}} | *** Back Extra :progit: ** The first thing that reset will do is move what ={{c1::HEAD}}= points to. This isn't the same as {{c2::changing HEAD itself}}, which is what {{c3::checkout}} does. :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Cloze :ANKI_NOTE_ID: 1766291804369 :ANKI_NOTE_HASH: 7f7ad5abef449f622089f0213cfcb6ca :ANKI_PREPEND_HEADING: t :END: *** Text :progit: The first thing that reset will do is move what ={{c1::HEAD}}= points to. This isn't the same as {{c2::changing HEAD itself}}, which is what {{c3::checkout}} does. =git reset= moves the {{c4::branch}} that =HEAD= is pointing to *** Back Extra :progit: ** What is =HEAD~=? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1766293156597 :ANKI_NOTE_HASH: 7441f9bf79965c2dee22eb2e6bd55b55 :END: the parent of =HEAD= ** What are the 3 levels of =git reset=? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1766293156598 :ANKI_NOTE_HASH: ea5ee522007627b6f53610f5d4e7fe33 :END: 1. =git reset --soft HEAD~= 2. =git reset [--mixed] HEAD~= 3. =git reset --hard HEAD~= ** What effect does =git reset HEAD~= have on your git state? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1766293156599 :ANKI_NOTE_HASH: 3d1f7f37ad9c42484cfa94573344dcee :END: undid the last commit (changes branch =HEAD= points to) and unstaged everything (updates =index= with snapshot of =HEAD~1=) ** What do the 3 levels of git resetting (=--soft=, =--mixed=, =--hard=) do? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1766293156600 :ANKI_NOTE_HASH: 5ef39dfcdb560ed64c6a278c1a450057 :END: 1. moves branch that =HEAD= points to [[file:img/progit-fig144.png]] [[file:img/progit-fig145.png]] 2. updates index with contents of new snapshot that =HEAD= points to. [[file:img/progit-fig146.png]] 3. makes working directory look like index [[file:img/progit-fig147.png]] ** What does =git reset file.txt= do? What does this mean practically? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1766293156601 :ANKI_NOTE_HASH: b5d4528f7c90f6a3b8dcb2fd6cc3846a :END: [[file:img/progit-fig147.png]] [[file:img/progit-fig148.png]] 1. moving branch that =HEAD= points to is skipped (files are not commits!) 2. make index look like =HEAD=. practically this _unstages_ the file. ** How can you squash commits with =git reset=? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1766293156602 :ANKI_NOTE_HASH: b988f361cd8633b34edba9893f317724 :END: =git reset --soft HEAD~2= [[file:img/progit-fig151.png]] =git commit= [[file:img/progit-fig152.png]] [[file:img/progit-fig153.png]] ** Whilst =reset= will move the {{c1::branch}} that =HEAD= points to, =checkout= will {{c2::move =HEAD= itself to point to another branch}} :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Cloze :ANKI_PREPEND_HEADING: t :ANKI_NOTE_ID: 1766292800939 :ANKI_NOTE_HASH: 33113ad1b85c9b58b481fb6e20dd605c :END: *** Text :progit: Whilst =reset= will move the {{c1::branch}} that =HEAD= points to, =checkout= will {{c2::move =HEAD= itself to point to another branch}} [[file:img/progit-fig154.png]] *** Back Extra :progit: ** Table :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Cloze :ANKI_NOTE_ID: 1766293089154 :ANKI_NOTE_HASH: bf766bd5baf99b2174ea2dc4e0ccc8e5 :END: *** Text :progit: | | =HEAD= | *Index* | *Workdir* | *WD Safe?* | |-----------------------------+---------------+--------------+--------------+---------------| | *Commit Level* | | | | | | =reset --soft [commit]= | {{c1::REF}} | {{c2::NO}} | {{c3::NO}} | {{c4::YES}} | | =reset [commit]= | {{c5::REF}} | {{c6::YES}} | {{c7::NO}} | {{c8::YES}} | | =reset --hard [commit]= | {{c9::REF}} | {{c10::YES}} | {{c11::YES}} | *{{c12::NO}}* | | =checkout = | {{c13::HEAD}} | {{c14::YES}} | {{c15::YES}} | {{c16::YES}} | | *File Level* | | | | | | =reset [commit] = | {{c17::NO}} | {{c18::YES}} | {{c19::NO}} | {{c20::YES}} | | =checkout [commit] = | {{c21::NO}} | {{c22::YES}} | {{c23::YES}} | *{{c24::NO}}* | ** How do you back out of a merge when you weren't expecting conflicts? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1766295785860 :ANKI_NOTE_HASH: 2ce97700d26a9e9730bc8ea8f8a0ab74 :END: =git merge --abort= ** What does =git reset --hard =HEAD== do? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1766295785869 :ANKI_NOTE_HASH: 1e4b0a2528678951deae4902bd26e870 :END: reverts the repository back to the last committed state ** What options can be used to merge when the only differences between the code is whitespace? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1766295785872 :ANKI_NOTE_HASH: bd2a9d4e5c6f9ce4187759921aec34e6 :END: =git merge -Xignore-space-change = or instead use the flag =-Xignore-all-space= ** What is the difference between =-Xignore-all-space= and =-Xignore-space-change=? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1766295785875 :ANKI_NOTE_HASH: 6566f584f7c5402b04574caadcaa04f0 :END: "all-space" ignores whitespace completely when comparing lines, "space-change" treats sequences of one or more whitespace characters as equivalent ** When you get into a merge-conflict state, how can you export the files from the common state, their state and your state? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1766295785877 :ANKI_NOTE_HASH: 0f97f60189443426aad4823cc20f7cb6 :END: #+BEGIN_SRC bash $ git show :1:hello.rb > hello.common.rb $ git show :2:hello.rb > hello.ours.rb $ git show :3:hello.rb > hello.theirs.rb #+END_SRC ** What does =git ls-files -u= do when in a merge conflict state? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1766295785880 :ANKI_NOTE_HASH: 3af7bfec19535ccfd33da2708cb34adb :END: #+BEGIN_SRC bash $ git ls-files -u 100755 ac51efdc3df4f4fd328d1a02ad05331d8e2c9111 1 hello.rb 100755 36c06c8752c78d2aff89571132f3bf7841a7b5c3 2 hello.rb 100755 e85207e04dfdd5eb0a1e9febbc67fd837c44a1cd 3 hello.rb #+END_SRC shows the conflicting files with 1. common ancestor 2. yours 3. theirs ** What does =git diff --ours= do? What about the =--theirs= flag? What's the last flag in this vein? =git diff --base= :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1766295785883 :ANKI_NOTE_HASH: 38fa9b30b845f86308c0b8e41db15cb2 :END: =--ourss= shows what the merge introduced. =--theirs= shows us how the merge differed on their side =--base= shows how the file was changed on both sides. ** What does =git checkout --conflict = do? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_PREPEND_HEADING: t :ANKI_NOTE_ID: 1766295785885 :ANKI_NOTE_HASH: 41d129f0d45055a0618b25919b060217 :END: What are the options available to =conflict=? *** Back :progit: =diff3= or =merge= (default) =diff3= will show base markers on ==. this command resets the markers on a git conflicted file. ** How can we get a full list of the unique commits that were included in either branch involved in the merge? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1766295785888 :ANKI_NOTE_HASH: e339a9760754e0e0d497279baec7e324 :END: triple-dot syntax: =git log --oneline --left-right HEAD...MERGE_HEAD= ** How to only see those commits that affect files that are merge-conflicted? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1766295785890 :ANKI_NOTE_HASH: c3d31c73b3466f8a6db3a2a80fb070af :END: =git log --merge= usefully, you probably do want to add =--oneline= and =--left-right= ** Whan you run =git diff= while in a conflicted merge state, you only get ... :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1766295785893 :ANKI_NOTE_HASH: f499d42b2d76e32af01712a1c123ece9 :END: what is currently in a conflicted state. Note: this can be helpful to see what needs to be resolved. ** What are the three steps that =reset --hard= goes through? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1766295785895 :ANKI_NOTE_HASH: 5b37a4cdb9bd20014dfb99291db98f3b :END: 1. move the branch that =HEAD= points to 2. make index look like =HEAD= 3. make the working directory look like the index. ** What does =git revert= do? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1766295785898 :ANKI_NOTE_HASH: 1d98ef27b3aadedca50fc75248a0fefa :END: makes a new commit which undoes all the changes from an existing one. ** What do the =-Xours= and =-Xtheirs= flags do? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1766295785900 :ANKI_NOTE_HASH: c5ceddfe2539e04dac8654a68a448073 :END: allow us to choose which files to use in merge conflicts. ** What is the flag to provide a merge strategy for =git merge=? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1766295785902 :ANKI_NOTE_HASH: 34ef79dda15de35193da834640df5d44 :END: =-s=; can take =recursive= (default) or =ours= as options. potentially others are available too. ** What does =rerere= stand for? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1766295785905 :ANKI_NOTE_HASH: 3838a63804f7e2964259533732f9f4d5 :END: "re-use recorderd resolution" ** What does the =-L= flag do in =git blame=? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1766295785907 :ANKI_NOTE_HASH: 2ade573d50e4266008268f05d8d5c1b4 :END: restricts the lines of the == in question ** What does the =-C= option do in =git blame=? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1766295785910 :ANKI_NOTE_HASH: a74718d7b6a29cb6567ea714a85b268b :END: tries to track down where (else) (in the codebase) the lines in the current file originated from ** What does =git bisect= do? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1766295785913 :ANKI_NOTE_HASH: 98861fe22028d7476943639e25fcd2c4 :END: helps us find the *commit* that is broken with a binary search ** How does =git bisect= work? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1766295785915 :ANKI_NOTE_HASH: 2ee8399a7a334feabd7d119530857443 :END: start with =git bisect start=, then follow it up with =git bisect bad=. this will tell it we are in a broken state. then =git bisect good = where == is the commit that is working. repeat this good, bad cycle until git finds the offending commit. run =git bisect reset= when done. this resets =HEAD=. ** How to initialise submodules after a =git clone=? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_PREPEND_HEADING: t :ANKI_NOTE_ID: 1766295785918 :ANKI_NOTE_HASH: 357848f7e9242c426e5c7c9f5a479c10 :END: Can we do it from the =git clone= command directly? *** Back :progit: =git submodule init= followed by =git submodule update= or indeed: =git clone --recurse-submodules= ** How can you combine the =git submodule init= and =git submodule update= commands? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1766295785920 :ANKI_NOTE_HASH: bd11bbe15f0fcbf67a83cbb30f1b8a37 :END: =git submodule update --init=, but for good measure you should really also add the =--recursive= flag, in case those submodules have submodules too: i.e. =git submodule update --init --recursive= ** How to see what has changed in a submodule from the present repo? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1766295785922 :ANKI_NOTE_HASH: a6fcef38b79a80d9536e589bffb3d360 :END: =git diff --submodule= ** What does =git submodule update --remote= do? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1766295785925 :ANKI_NOTE_HASH: 24bb7d7a8a5dd9ca558dd9e196658bb4 :END: goes into all the submodules and basically runs =git fetch= followed by =git merge= ** How can we modify =git push= to only succeed if all submodule changes have already been pushed? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1766295785929 :ANKI_NOTE_HASH: 999c1e820365b025e67a9d131ebe1388 :END: =git push --recurse-submodules=check= Note: =--recurse-submodules=on-demand= will try to do the =git push= for you in all submodules. ** What does =git submodule foreach= do? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_PREPEND_HEADING: t :ANKI_NOTE_ID: 1766295785934 :ANKI_NOTE_HASH: b0d5511e82372f232667dcdde00839f5 :END: How can we use it to create a unified diff? *** Back :progit: =git diff; git submdoule foreach 'git diff'= ** What do you need to additionally do when checking out a branch with submodules / going to a branch without submodules? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1766295785938 :ANKI_NOTE_HASH: 1dc9eb97262d61327c32fc3695129fa4 :END: add the =recurse-submodules= flag to =git checkout= This (after git version > 2.13) takes care of placing the submodules in the right state for the branch we're on. ** How can you convert a subdirectory into a submodule? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_PREPEND_HEADING: t :ANKI_NOTE_ID: 1766295785942 :ANKI_NOTE_HASH: 5ce5840a464e0823dca8925855fb73be :END: What is wrong with simply doing =rm -f ; git submodule add ...subfolder.git=? *** Back :progit: we need to unstage the directory from git's index first! =git rm -r = will work ** What does =git rebase --onto c1 c2= do?= :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1766295785945 :ANKI_NOTE_HASH: 9e2d477fcb4cbbd152eec2defe27781a :END: Rebases the current branch onto =c1=, starting from commits after =c2=. In other words: take all commits reachable from HEAD but not from =c2=, and replay them onto =c1=. This is useful for moving a branch to a new base while excluding certain commits. ** What does =git bundle create repo.bundle HEAD master= do? :progit: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1766295785948 :ANKI_NOTE_HASH: f7fd8639d8bd47c57e8c2f7c4ed1e18e :END: creates a local file that contains the entire repo. you must add all the refs desired. it can later be unpacked with =git clone repo.bundle repo= as usual!