* 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? :git: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763629959831 :ANKI_NOTE_HASH: c624046693c2638f21d8e475610cb360 :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? :git: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763628836314 :ANKI_NOTE_HASH: 345194254614dae014c40588b1ef657c :END: SHA1 hash. 40 length. Hex; i.e. 0-9 + a-f ** What are the three main states files can reside in? :git: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763628836317 :ANKI_NOTE_HASH: 4e221309c4b87673c6511ca39002c469 :END: 1. modified 2. staged 3. committed ** What does the staging area look like? :git: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763628836319 :ANKI_NOTE_HASH: 1c7208e708f12ce654946c5ec3660697 :END: it is a _file_ called *index*. ** What are the three scopes of =git config= and where are each of the configuration files stored? :git: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763628836321 :ANKI_NOTE_HASH: 348371e4231f0f968f20dd547cb53549 :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=? :git: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763628836322 :ANKI_NOTE_HASH: 552558b7241ae3d6a898a6570bfdd066 :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? :git: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763628836324 :ANKI_NOTE_HASH: 4274727fee4b07b26241fffdd9778859 :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? :git: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763628836325 :ANKI_NOTE_HASH: 5555e68d564b26ef5b84da3c88ba2990 :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? :git: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763628836327 :ANKI_NOTE_HASH: cde3847394fca71bb8c306dec41c2d57 :END: trick question; =git add= automatically adds directories recursively. ** What does =git add= do? :git: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763628836328 :ANKI_NOTE_HASH: 5d597fe0a15d47f7e66c80e3562af84e :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? :git: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_PREPEND_HEADING: t :ANKI_NOTE_ID: 1763629926820 :ANKI_NOTE_HASH: 51cd7d76242bdd62b678d6de67975fb0 :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=? :git: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763628836331 :ANKI_NOTE_HASH: 866c02f2597fae6c8a6e7ccc723b576c :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? :git: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763628836333 :ANKI_NOTE_HASH: 0fc8c5fb7486b56bb7ad10190db7863c :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? :git: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_PREPEND_HEADING: t :ANKI_NOTE_ID: 1763628836334 :ANKI_NOTE_HASH: b69b3194758ea5021efacfb4a9b12ce3 :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? :git: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_PREPEND_HEADING: t :ANKI_NOTE_ID: 1763629926825 :ANKI_NOTE_HASH: 51320c3469150c174e4e013f2cb1d51a :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? :git: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763628836337 :ANKI_NOTE_HASH: 834d5c190cec2767927c33c7381f5963 :END: no, it can have *one* in each subdirectory if required. ** What does =git diff= do? :git: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763628836339 :ANKI_NOTE_HASH: 2077e20d702c518eec161cb1a1a41adb :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? :git: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763628836340 :ANKI_NOTE_HASH: 5b60e2464f9286245ef4c4a6c9e6f3d8 :END: =git diff --staged= ** What is the difference between =git diff --staged= and =git diff --cached=? What do they do? :git: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763628836341 :ANKI_NOTE_HASH: d351a853b66c36a5b7da18485a7a92b3 :END: they're synonyms! shows the /diff/ between last commit and what is staged ** What does =-v= do in =git commit=? :git: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763628836343 :ANKI_NOTE_HASH: c0382fe68a443b590e87df3e84296e6e :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? :git: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763628836344 :ANKI_NOTE_HASH: d6ec5004f89c3200e3bd20f608ae873f :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? :git: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763628836346 :ANKI_NOTE_HASH: aa00032bfc6e8830824d605638f5075b :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=? :git: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763628836347 :ANKI_NOTE_HASH: 93de1c52d2be7c3513a166851caa99d6 :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? :git: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763628836349 :ANKI_NOTE_HASH: abf5b06c3cfd389eca7094e73545aa96 :END: =git rm --cached = ** What order does =git log= show commits in? :git: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763628836350 :ANKI_NOTE_HASH: d56065d3b76a7f70626b69b95092350e :END: reverse chronological order -- most recent commits first. ** What does =git log -p -2= do? :git: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763628836351 :ANKI_NOTE_HASH: 93e492cd38a06a6b6780254fadad7142 :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? :git: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763628836353 :ANKI_NOTE_HASH: 8842885e0cd3c9379b739a8014d40612 :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? :git: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763628836354 :ANKI_NOTE_HASH: a3ea0c1341d8c259e9a47baad86d402b :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? :git: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763628836355 :ANKI_NOTE_HASH: 04fea03df8b34497e0566409aedcee4f :END: =git log -s = shows only those commits that changed the number of occurrences of =function_name= ** How can you filter in =git log= based on path? where in the command should this filter go? :git: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763628836357 :ANKI_NOTE_HASH: 4a45b76389dab6a5c47091ee471f8ea3 :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=? :git: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763628836358 :ANKI_NOTE_HASH: bc51922a94ed11965040fc8389a1fdbc :END: =--no-merges= ** How can you fix a commit message / add an extra file to your commit (that hasn't been pushed yet)? :git: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763628836360 :ANKI_NOTE_HASH: da1a62587db71e04a94ef9060690c134 :END: =git commit --amend= note that you get a new hash, and the old commit never exists in the history. ** What does =git checkout -- = do? Are there perils? :git: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763628836361 :ANKI_NOTE_HASH: 6148cae027c1eae89920a1879bdae748 :END: Yes, perils - you can lose work! It deletes changes and brings the file back to the last staged or committed version. ** Which 2 commands does =git reset= replace? :git: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763628836362 :ANKI_NOTE_HASH: 1a894dc684d31a2bd37151d74e2d1589 :END: =git reset HEAD = and =git checkout -- = ** What is the command to add a new remote with shortname and URL? :git: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763628836363 :ANKI_NOTE_HASH: 22cd9937b8a725af23f64dc1dcbd8837 :END: =git remote add = ** What does =git fetch = do? :git: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763628836365 :ANKI_NOTE_HASH: 56e09e099ae4a7db4625309e230c39e4 :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? :git: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763628836366 :ANKI_NOTE_HASH: 4c6328a96c1f6ca5a22e441ee382d8d9 :END: it unstages the file. (but I thought =git rm --cached= does that too...) ** How to see the URLs of *all* the remotes? What about a single remote? :git: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763628836367 :ANKI_NOTE_HASH: 8a2322b7b43c888c474164c3f5d1b4cd :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)? :git: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763628836368 :ANKI_NOTE_HASH: b0e66c7a8eb7bf1039f23d280a272c72 :END: =git tag= with optional =-l= that respects globs =-l ""= ** What are the 2 types of tags? What do they do? :git: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763628836369 :ANKI_NOTE_HASH: 6420673bcc9a961c1279b28c738c51e2 :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? :git: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763628836372 :ANKI_NOTE_HASH: 0782acbff1fa79a2a6b57cfde9d0b901 :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? :git: :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763628836371 :ANKI_NOTE_HASH: 46d0bbdf727191a6b94f17baff14c5d7 :END: =git tag -a -m ""= =git tag -a = =git show = ** When is *rebasing* a bad idea? :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763944597353 :ANKI_NOTE_HASH: 1c84f3d86b7fa518888df4293af71752 :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? :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763944597366 :ANKI_NOTE_HASH: b85f50437b9cdb4dcc21e01651d46e93 :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? :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_PREPEND_HEADING: t :ANKI_NOTE_ID: 1763944597389 :ANKI_NOTE_HASH: 1134d89ab05e6d088f2613f808674594 :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? :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763947431084 :ANKI_NOTE_HASH: 22df707cd9fb701837ab8d76f489c2a6 :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? :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763947431105 :ANKI_NOTE_HASH: 87ca5c9e2da5abf73d422b0fc1c506d5 :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? :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763947431113 :ANKI_NOTE_HASH: fa1dc1fbedba6f9c1cf4ac9a10f433db :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=? :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763947431119 :ANKI_NOTE_HASH: bd11b048a074723daaa4c81ff6dcd75f :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? :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763947431127 :ANKI_NOTE_HASH: a3b1af8637049a450605dd2e61492cfb :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/=}} :PROPERTIES: :ANKI_NOTE_TYPE: Cloze :ANKI_NOTE_ID: 1763947431139 :ANKI_NOTE_HASH: 7bd13a5475a1461745b2cce0c9b5e837 :END: ** What is =git checkout serverfix= an alias for, where you don't have the remote serverfix branch? :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763947431145 :ANKI_NOTE_HASH: 0120f12f09ae4a1b1fe04f00f652834b :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? :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763947431152 :ANKI_NOTE_HASH: 7f59596789402c23c0347b506f678b0a :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? :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763947431157 :ANKI_NOTE_HASH: 01420a95d7c036c54c1e36abc3ceea0d :END: =git push = (will creating a branch and then running =git push= automatically push the branch?) ** How to pull changes down from a certain remote? :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763947431162 :ANKI_NOTE_HASH: 07f5c408bda8561688018ed1124c6a9d :END: =git fetch = ** How can we get a full list of remote references? :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763947431165 :ANKI_NOTE_HASH: 6417c4aed3daece8724fdaf957d9ab10 :END: =git ls-remote = OR =git remote show = ** How do you rename a branch? Are there perils? :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763947431173 :ANKI_NOTE_HASH: c9aa9a36b00dd94e57b4b84a32e7e1c8 :END: Yes, perils! Check collaborators. =git branch --move = (performs the change locally) =git push --set-upstream origin = (pushes the changes to the remote) =git push origin --delete = (deletes old branch from the remote) ** What does =git branch --no-merged master= do? :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763947431178 :ANKI_NOTE_HASH: 3581f6124d15c4ef72b8a0996e72a3cc :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=? :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763947431182 :ANKI_NOTE_HASH: da08ac34f03e96dc44120236f422ba73 :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=? :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763947431189 :ANKI_NOTE_HASH: 74d0965fc35c3b7a7390ab389b82d17e :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? :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763949559427 :ANKI_NOTE_HASH: c73461ee76bd266763537d9d01167835 :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? :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763949559435 :ANKI_NOTE_HASH: b116cef7a25f1c3d5a642f11985b873e :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=? :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763949559440 :ANKI_NOTE_HASH: a266acfee369fd10892c7eadf90fb8da :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"? :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763949559461 :ANKI_NOTE_HASH: 9412b9842a2d8548a5edafb7599f5e3d :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? :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763949559466 :ANKI_NOTE_HASH: 4cb37676c218ce9647733f8bdd1fd19c :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. :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763949559473 :ANKI_NOTE_HASH: c8850816bba1aaf25a3ef713ff8bd925 :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? :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763949559497 :ANKI_NOTE_HASH: a7eeefa177717fd387e8a2b81ebeb109 :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? :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763949559503 :ANKI_NOTE_HASH: 254ed7ac16c76b8df8c512f4e9378884 :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 :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763949559507 :ANKI_NOTE_HASH: 8368e7b31a7fb5a423f03a8cdbfad839 :END: =git log --oneline --decorate= [[file:img/head-branch.png]] ** How does Git know what branch you're on? :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763949559512 :ANKI_NOTE_HASH: dc2092b89f799b9cd1b911cf49706b5e :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? :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763949559518 :ANKI_NOTE_HASH: 49f62260caf81bf36596f767b4f5c2da :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? :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763949559522 :ANKI_NOTE_HASH: b9af0d5954ee646e792a8abfc6bfd1e8 :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. :PROPERTIES: :ANKI_NOTE_TYPE: Cloze :ANKI_NOTE_ID: 1763949559529 :ANKI_NOTE_HASH: 4ceee5895a54bc0abbea2a7911dcc879 :END: ** When does a file get a checksum? What does this imply has happened? :PROPERTIES: :ANKI_NOTE_TYPE: Basic :ANKI_NOTE_ID: 1763949559535 :ANKI_NOTE_HASH: ff2764a49ecb8d3f2f5ea6665a8ad71b :END: when the file is _staged_. implies a verison of the file has been stored. (called blobs) # local variables: # eval: (anki-editor-mode +1) # end: