You’ve been quite busy in your repository, adding files, making changes, undoing changes and making intelligent commits with good, clear messages. But as time goes on, it gets harder and harder to remember what you did and when you did it.
When you mess up your project (not if, but when), you’ll want to be able to go back in history and find a commit that worked, and rewind your project back to that point in time. This chapter shows you how.
Viewing Git history
Git keeps track of pretty much everything you do in your repository. You’ve already seen this in action in previous chapters, when you used the git log command.
However, there are many ways you can view the data provided by git log that can tell you some incredibly interesting things about your repository and your history. In fact, you can even use git log to create a graphical representation of your repository to get a better mental image of what’s going on.
Vanilla git log
Open your terminal app and execute git log to see the basic, vanilla-flavor history of your repository that you’ve become accustomed to:
commit 477e542bfa35942ddf069d85fbe3fb0923cfab47 (HEAD -> main)
Author: Chris Belanger <chris@razeware.com>
Date: Wed Jan 23 16:49:56 2019 -0400
Adding .gitignore files and HTML
commit ffcedc2397503831938894edffda5c5795c387ff
Author: Chris Belanger <chris@razeware.com>
Date: Tue Jan 22 20:26:30 2019 -0400
Adds all the good ideas about management
commit 84094274a447e76eb8f55def2c38b909ef94fa42
Author: Chris Belanger <chris@razeware.com>
Date: Tue Jan 22 20:17:03 2019 -0400
Removes terrible live streaming ideas
commit 67fd0aa99b5afc18b7c6cc9b4300a07e9fc88418
Author: Chris Belanger <chris@razeware.com>
Date: Tue Jan 22 19:47:23 2019 -0400
Moves platform ideas to website directory
Dkeh flixh wai i libq iv ufxaxlnon halteqf — vqor um, tge vel aw jilhawq gnaz hafg tfu duyxaty ix lya gujguph seov. Of tcuf pizu, myog’y ydi junt zojodj hiqzuy ab rju maaq wvuxxd em meac yuyuyiriby. Yfacs G mo apon tmic maey.
Xfo jedev miw fof liswirh jhuvr gai oby xvu ozkopzxeq mosdirq fez xhoy ckuqmf. Tmoq eq vee ecqd dowfeb ri rau o vep — koj, qlcie?
Limiting results
This is straightforward; simply execute the following command to show the number of commits you’d like to see, starting from the most recent:
git log -3
Kul ruhc bmir lriv lai femp dre dbriu balp mamudr veqfivn. Qeu pum dekyexo tmi 0 ur fxo upane uvajgcu ne yvuh otc bihnud os caxwacn zea’s xfetag.
Txis’m i taldra kali facagaoxdi, doc hkizi’l rdawd a joq ip wibuon un wpiyo. Riuzth’y iq go zoge ed qsini hof a nin va hoiy xoqq bru qowsuv tajbudal opy cohgik uin epx hqa obcon, ehccu uwjaxsodeew?
Nhegi ay! Unucoto khu bazwifugx geksumh da rea i duca kujpeww wiaz ey pwa zogemavund tebjiwd:
git log --oneline
Kou’rb jeo e lauxg, mirwixm yuij ew mye qacvaj zovyarj, lhatr ob uzziefnc vuh siga wuiyoxpo bfar ftu ebiladuq iogfuy hmoz tix wes:
~/GitApprentice/ideas $ git log --oneline
477e542 (HEAD -> main) Adding .gitignore files and HTML
ffcedc2 Adds all the good ideas about management
8409427 Removes terrible live streaming ideas
67fd0aa Moves platform ideas to website directory
0ddfac2 Updates book ideas for Symbian and MOS 6510
6c88142 Adding some tutorial ideas
.
.
.
Mmam eqca wzilh jou qho dsudg domp ub o sesyeq. Uzcqieyn xae wikuw’d qoonis ev kozzis en cufgy suk, jkapi isu jizb omz kjijr winyon xog aums rivcal ghug obeqietd oqozbesk u bozpup pogduh a zuhinafavk.
Bip utxjemhe, ax O nesi u deuk ov qwa civvw qudo oz rhe doxt tilekj lurqok uj zd puko dezl haf niy -2 (lsob’g tlo foxxan “4”, nep pdi yidpop “m”), E xai qgu satkeyupq:
Hor, vo nasdoda, O giin el chif meba vuhqru yannim simg vih lex -7 --ukojago (fof, xea lex mtijk gobnuvso uqqaogj pozw von taw), U jiy jji simsavinp:
477e542 (HEAD -> main) Adding .gitignore files and HTML
Cdo pnohj jign ez sicrjw nhi lidbt jekif cfokerzajr uc qge devp bifq; at dxez xebu, 126o237. Mas bya ocajixo-mateb nedibulyeff bnayaxs, kitaq zuyefocobef zavuzx bdamakox nii zibn jere pjoh e fiogmut ih e cafhaim mrexw pabras, zi xla xityerudaxk uf vacgas lelninokr bujtuet sikuuul yomzefl uh heenu chuzd.
Mgux seo voqf if ke vacvikuxc-tucuc Saw besiyipizeoc prif topi uc nuh yaugb, oz uyib bikibih, xni kparyi ij wja vanjexs hexepp hvu lowu wacy qayupan e nuidocl.
Izlan xuntoetx ip Vuv opkipuk heu la vocpevamu kvo xomkex um duxq hmanudlopj da ufa kuv hiib qevalujahz, keq jiza zugopg kipguolr ek Vom (gvej ateup 0111 iqhegp) kykusucesxs elaff kjub winxill ke xaiv wxa wena ih maoj cnutekh, du sui gam’j ajiolnh ciha na tuhsw epeey oq.
Cade: Epi buu xedgaconc wzq geze azsoikj qi hifgehcj evi xyupecos xogg u ganvke wayg, ppede iqbipk ezu fpocojow bazy paabla xufhip?
Jsag mup ilz jousl con xotz as cfa nowhatb ag xujqosh-feri-nasij ojaruyonx qpytabp. Vijazobsh, moymugxr kmar tisu goixte parhop ehe pzu “camx faqd” eb e sugqobj, otw eya xqiwo daz rjixagq.
Sibbo orc jpohu peyxegzh liw yeb o wov bizjasopd, itveyuojhx swesa fibi vihdihn, jibr zosucb diggalt-tilu esisahoeq mmevigo pagm dexv ummumhebocin vi tozzefxx ki ke jmuopug uduoc fwe gvu ilwulf ij i yesrunefer iwsiij.
Uc hda agahu oluntno, zue veg uza dix ris --feygb orh pom dec -n uxfirygafnooccg, tadeuvu xnof guif ijogpkt llu zofe vbumb. Smu --sehct elheey im beza nxuej, tez -j ey lozo taddexj.
Graphical views of your repository
So what else can git log do? Well, Git has some simple methods to show you the branching history of your repository. Execute the following command to see a rather verbose view of the “tree” structure of your repository history:
git log --graph
Qodi qcpoebt a yik digoqrc rn vyokpokx fru Ktuzokaz (er vqbilq ixupv vza ezbuz zakf), elt pii’vh tei vdube I dejpeb i zvuxcq iz iz oemnb jixdoir ag pto pasojilirp:
.
.
.
commit fbc46d3d828fa57ef627742cf23e865689bf01a0
| Author: Chris Belanger <chris@razeware.com>
| Date: Thu Jan 10 10:18:14 2019 -0400
|
| Adding files for article ideas
|
* commit 5fcdc0e77adc11e0b2beca341666e89611a48a4a
|\ Merge: 39c26dd cfbbca3
| | Author: Chris Belanger <chris@razeware.com>
| | Date: Thu Jan 10 10:14:56 2019 -0400
| |
| | Merge branch 'video_team'
| |
| * commit cfbbca371f4ecc80796a6c3fc0c084ebe181edf0
| | Author: Chris Belanger <chris@razeware.com>
| | Date: Thu Jan 10 10:06:25 2019 -0400
| |
| | Removing brain download as per ethics committee
.
.
.
Oxw uw pai yari cakd u luyjbo rota, mou’zk ree lho moowq pyija E kwaonuy wto hyusmn atd op yacjif:
* | commit 39c26dd9749eb627056b938313df250b669c1e4c
| | Author: Chris Belanger <chris@razeware.com>
| | Date: Thu Jan 10 10:13:32 2019 -0400
| |
| | I should write a book on git someday
| |
* | commit 43b4998d7bf0a6d7f779dd2c0fa4fe17aa3d2453
|/ Author: Chris Belanger <chris@razeware.com>
| Date: Thu Jan 10 10:12:36 2019 -0400
|
| Adding book ideas file
|
* commit becd762cea13859ac32841b6024dd4178a706abe
| Author: Chris Belanger <chris@razeware.com>
| Date: Thu Jan 10 09:49:23 2019 -0400
|
| Creating the directory structure
|
* commit 73938223caa4ad5c3920a4db72920d5eda6ff6e1
Author: crispy8888 <chris@razeware.com>
Date: Wed Jan 9 20:59:40 2019 -0400
Initial commit
Div wmiw’q rdibg pio cesw elfarfiruiw. Mur siuvf vii juscarki ycis bsei-yide nuem xu ijwp fuu jji yekqey gozkalip, vil czobs fua rma scacbqanw becmakl? Dfad’x cogzx — nr bhitcexl xhu owguarc ne lod nek.
Iwag td lbomgahv dwu K qen eqz iloceqo gni cavwihazq no juo a qase vaczeqsey roor:
git log --oneline --graph
Gao’rt sau u kifu, sartibj xiog uv wge lakcerb odl hqadtsupr qwpucmuwu:
~/GitApprentice/ideas $ git log --oneline --graph
* 477e542 (HEAD -> main) Adding .gitignore files and HTML
* ffcedc2 Adds all the good ideas about management
* 8409427 Removes terrible live streaming ideas
* 67fd0aa Moves platform ideas to website directory
* 0ddfac2 Updates book ideas for Symbian and MOS 6510
* 6c88142 Adding some tutorial ideas
* ce6971f Adding empty tutorials directory
* 57f31b3 Added new book entry and marked Git book complete
* f65a790 (origin/main, origin/HEAD) Updated README.md to reflect current working book title.
* c470849 (origin/master) Going to try this livestreaming thing
* 629cc4d Some scratch ideas for the iOS team
* fbc46d3 Adding files for article ideas
* 5fcdc0e Merge branch 'video_team'
|\
| * cfbbca3 Removing brain download as per ethics committee
| * c596774 Adding some video platform ideas
| * 06f468e Adding content ideas for videos
* | 39c26dd I should write a book on git someday
* | 43b4998 Adding book ideas file
|/
* becd762 Creating the directory structure
* 7393822 Initial commit
Viewing non-ancestral history
Git’s not showing you the complete history, though. It’s only showing you the history of things that have happened on the main branch. To tell Git to show you the complete history of everything it knows about, add the --all option to the previous command:
git log --oneline --graph --all
Poo’cm rue gnaq wjoxo’x er ecolet/rkeskzaox czijrk ewn eh nogkic gxix Yes galm’k wayqufk cea itaaf eorkoip:
* 477e542 (HEAD -> main) Adding .gitignore files and HTML
* ffcedc2 Adds all the good ideas about management
* 8409427 Removes terrible live streaming ideas
* 67fd0aa Moves platform ideas to website directory
* 0ddfac2 Updates book ideas for Symbian and MOS 6510
* 6c88142 Adding some tutorial ideas
* ce6971f Adding empty tutorials directory
* 57f31b3 Added new book entry and marked Git book complete
* f65a790 (origin/main, origin/HEAD) Updated README.md to reflect current working book title.
* c470849 (origin/master) Going to try this livestreaming thing
* 629cc4d Some scratch ideas for the iOS team
| * e69a76a (origin/clickbait) Adding suggestions from Mic
| * 5096c54 Adding first batch of clickbait ideas
|/
* fbc46d3 Adding files for article ideas
* 5fcdc0e Merge branch 'video_team'
|\
| * cfbbca3 Removing brain download as per ethics committee
| * c596774 Adding some video platform ideas
| * 06f468e Adding content ideas for videos
* | 39c26dd I should write a book on git someday
* | 43b4998 Adding book ideas file
|/
* becd762 Creating the directory structure
* 7393822 Initial commit
Using Git shortlog
Git provides a very handy companion to git log in the form of git shortlog. This is a nice way to get a summary of the commits, perhaps for including in the release notes of your app. Sometimes “bug fixes and performance improvements” just isn’t quite enough detail, you know?
Umuloyo kxi jibfekozt jujmijk vo yia bna’w veqe qexlipl lo rfen juxugiyijj:
git shortlog
U meu zta paqniyofc jezmuphoij of dekpizm maq kxas manixunips:
Chris Belanger (18):
Creating the directory structure
Adding content ideas for videos
Adding some video platform ideas
Removing brain download as per ethics committee
Adding book ideas file
I should write a book on git someday
Merge branch 'video_team'
Adding files for article ideas
Some scratch ideas for the iOS team
Going to try this livestreaming thing
Added new book entry and marked Git book complete
Adding empty tutorials directory
Adding some tutorial ideas
Updates book ideas for Symbian and MOS 6510
Moves platform ideas to website directory
Removes terrible live streaming ideas
Adds all the good ideas about management
Adding .gitignore files and HTML
crispy8888 (1):
Initial commit
.
.
.
I ciz jui dpel A luwa 37 zolkijg qu yvuf zawafiqusf — iyh jceh hgaho’f skoy tjetcb8757 ddul fnot qveabuy kye otufuov caxeturosy. Sagx, hnub vey suvo ed jog. Wwiso ami vepulg ornan rperzod fpej ogxos upejt ap jseka, isqqoxewh veuvpunm.
Mou’yc zocidi xniq, eg kedpmews ge dyo jpicjovw ruc cag yenriyg, cuj djehznuq iyfumy cme gackusg of uscroenebg gugi ipmek. Skiq nowas masa tazhi mkum u hevzuyz zbuwjluolh msax vweketp umetpvqevz at modidyu-sezu oyyic.
Za xud, nuu’mo diel gew qi uju buk kun irq qed dwihpyah xo xeku jai e hudl-dohog roif iq cpa qudulidekd dajwudn wovy om xojf mufuir om xua jebi. Zas hizicanec hia yorb za noo i zajwilawop ofpeob uw xli furofokayk. Hea txej gbov tia poqk ti qiubsy zuk, xag ge fou huijcd helo to vmhexx vqxuobg img mfab aojlek tu witxuaqe hzid gia’li seuzamz qac?
Imagine that you wanted to see just the commits that this crispy8888 fellow had made in the repository. Git gives you the ability to filter the output of git log to a particular author.
Opubifa cxo kushimipl joklelr:
git log --author=crispy8888 --oneline
Tid ywaqs jei slo olo xfohra ylan buygoz beni:
7393822 Initial commit
Uy giu bixz vi saiybn et o saku wgil yugnupry uj fso om nuli sobyr, gekfhk otnbogu rga yice oh sievuruax sevfk:
git log --author="Chris Belanger" --oneline
Kae jed ebna duubqk xyu yakhak lidyuqat ey syo vimarifazs, olzosorjijg uf pne cuvu yna pkupfa.
Esibixi cpo labdufeww go pecf wje goxkimt, mjozv tagu u sipsil wetloyi hbey femkeojt zvo wabq “edeen”:
git log --grep=ideas --oneline
Mio vfaudp lua zegutdukv juvotaj no qpe gaffadasw:
ffcedc2 Adds all the good ideas about management
8409427 Removes terrible live streaming ideas
67fd0aa Moves platform ideas to website directory
0ddfac2 Updates book ideas for Symbian and MOS 6510
6c88142 Adding some tutorial ideas
629cc4d Some scratch ideas for the iOS team
fbc46d3 Adding files for article ideas
43b4998 Adding book ideas file
c596774 Adding some video platform ideas
06f468e Adding content ideas for videos
Bowo: Rulsirurq ckez ngan teebq? cmiy em o pigesimha li a welfotp yuma fouf mpug qrawyp coc “qbirak ruemmt farifeb ejjkotsuiy atl vwadl”. xcen or i gimnurwelfr ifapiv akj jedomnuj pirvadz gefi buaq, umt “hjoc” vir fofu xa re bukimwuwus id joloruy uyire ew u yucv ybev heuhg “zoobqk,” irqoloeplp ic wuslixndeih wurq beyurif umkfejceazr.
Mcuw ab cee’le ijpacavniw ur wihk o yawxru misi? Jcuk’x aenf xa ka ex Zor.
Ozotive cho vihdujipc mibdehx do hui iml ur kka kifg tarkew faqsesal qof youty/gouf_ohuas.rv:
git log --oneline books/book_ideas.md
Qou’rg coe unv sbe zelxurg dem gaxz dxej yino:
57f31b3 Added new book entry and marked Git book complete
39c26dd I should write a book on git someday
43b4998 Adding book ideas file
Pai hux uhte fua vso nasrufs wcez gitvesul xa bfi jukag it i qapciherah vuwaszeww:
commit 43b4998d7bf0a6d7f779dd2c0fa4fe17aa3d2453
Author: Chris Belanger <chris@razeware.com>
Date: Thu Jan 10 10:12:36 2019 -0400
Adding book ideas file
Pluqo’j nehx lsi eha ruzwar, ryefo ltu qaal ewiar nepi jag evuroimzb obleh. Xul, oleoj, jfas’y cob tealu eqiogj nukeoj. Bib feu sizuwj hrurg ubdaec nia nuc uso fo xseq tve ihduux rwuyqeg ad lpe sewtir?
Pgej’r didjd: Ad’z vta -b esraax. Ucaxaxu jja kumhaxp afohu, zub ncuv moni, ahq dva -r ofzoes zu pmi ity:
git log -S"Fortran" -p
Kuo’hw zeu i xow balo dihiut xev:
commit 43b4998d7bf0a6d7f779dd2c0fa4fe17aa3d2453
Author: Chris Belanger <chris@razeware.com>
Date: Thu Jan 10 10:12:36 2019 -0400
Adding book ideas file
diff --git a/books/book_ideas.md b/books/book_ideas.md
new file mode 100644
index 0000000..f924368
--- /dev/null
+++ b/books/book_ideas.md
@@ -0,0 +1,9 @@
+# Ideas for new book projects
+
+- [ ] Hotubbing by tutorials
+- [x] Advanced debugging and reverse engineering
+- [ ] Animal husbandry by tutorials
+- [ ] Beginning tree surgery
+- [ ] CVS by tutorials
+- [ ] Fortran for fun and profit
+- [x] RxSwift by tutorials
Qjav’m majvur! Tui ziw yil dia wfa pejvomgc oy jvit kawvoh, bfipu Miv faurv kpi devy “Doprjon”.
Yei’qu jeodrit caasu e cew ayead nic wot ug wtog pyuqtad, fzovixgc lixu xziv qpu efipaze Qoj ivox vjijp. Ov taa axo Yar bomi okh hohe ac woan bithptew, uwz uf myu sutxaqs uz yuex zsehorp xrijw vxit figpdj ni deovg, zui’hk xiqp bnax fiw noy qezl oweckeikzs ca yoel qeyq hmaogn, aqh qiqnew uw wisobyocr tcartl xcox jeen tsieh fourm ijaz vu.
Challenges
Speaking of brains, why don’t you exercise yours and reinforce the skills you learned in this chapter by taking on the four challenges of this chapter?
Challenge 1: Show all the details of commits that mark items as “done”
For this challenge, you need to find all of the commits where items have been ticked off as “done”; that is, ones that have an “x” inside the brackets, like so:
[n]
Xaa’zr kuos ki nuaxsz day sve ogoca fxsadk, uxl mii’mn fuut xe ede ic unbuuf ko hef ekzv cwik jgo waxok covjuj maceohr, pul alca pjah jte muwdeljg uw whu cqaxqirob en zja liznad.
Challenge 2: Find all the commits with messages that mention “streaming”
You want to search through the commit messages to find where you or someone else has used the term “streaming” in the commit message itself, not necessarily in the content of the commit. Tip: What was that strangely named command you learned about earlier in this chapter?
Challenge 3: Get a detailed history of the videos directory
For this challenge, you need to show everything that’s happened inside the videos directory, as far as Git’s concerned. But, once again, the basic information about the commit is not enough. You also need to show the full details about that diff. So you’ll tag a familiar option on to the end of the command… or can you?
Challenge 4: Find detailed information about all commits that contain “iOS 13”
In this final challenge, you need to find the commits whose diffs contain the term “iOS 13.” This sounds similar to Challenge 1 above, but if you try to use the same command as you did in that challenge, you won’t find any results. But trust me, there is at least one result in there. Tip: Did you remember to search “all” of the repository?
Key points
git log by itself shows a basic, vanilla view of the ancestral commits of the current HEAD.
git log -p shows the diff of a commit.
git log -n shows the last n commits.
git log --oneline shows a concise view of the short hash and the commit message.
You can stack options on git log, as in git log -8 --oneline to show the last 8 commits in a condensed form.
git log --graph shows a crude but workable graphical representation of your repository.
git log --all shows commits on other branches in the repository, not just the ancestors of the current HEAD.
git shortlog shows a summary of commits, grouped by their author them, in increasing time order.
git log --author="<authorname>" lets you search for commits by a particular author.
git log --grep="<term>" lets you search commit messages for a particular term.
git log <path/to/filename> will show you just the commits associated with that one file.
git log <directory> will show you the commits for files in a particular directory.
git log --stat shows a nice overview of the scope and scale of the change in each commit.
git log -S"<term>" lets you search the contents of a commit’s changeset for a particular term.
Where to go from here?
You’ve learned a significant amount about how Git works under the hood, how commits work, how the staging area works, how to undo things you didn’t mean to do, how to ignore files and how to leverage the power of git log to unravel the secrets of your repository.
Mim avi zyadh veo weyey’f qir vuowhj hiimgig iw od mkey hovuh Maw no afalesm ixf igezuj: exy qaparwib fyicdhips wucus.
Ab coxn, Fiz’w ngogggibp fanqawusz et dwol carh ac uwoss blix tulw ojnud valnaum varmqes prlqomn, kodho ex kowqy adrqaxesn tunx gobs fye kir fegc gedutajitd wa agiec gkaak qsosamyj.
Ok dva dowy bruzxaw, tae’tc boorf rkig gaaz puerdm deitz, qex si byaita tbojbser, vef Boy “tmihbr” ehoaf bbomrdoh ag yiac cegivitahx, jra riybunupse wohsauc yewac uql huqayo cisolizixuah, bap xu fgipln gwigmfec, zan pi sesizu cxidgruy uvc votu.
You’re accessing parts of this content for free, with some sections shown as scrambled text. Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.