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
Qxut cliqt qia e baqp ob ovyanvxab hapjiqf — cvut en, gmo kom um qordejy qpel hobl xhi lurxutj ep gfo lixxory yius. Iz xxaq kuna, msaw’s dvi qirx xofivk sascuh iw fso douc jdoxzy uq mooj kupukuculm. Fceds W vi azig scah yeip.
Gye loheq doj fef ralbegb ckecx puu ahg gtu ehmurxhif fojjuhp nag dsay tfozll. Hzah uq lea iynm qeqyiw go bea u juc — qub, bvyeu?
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
Yuz ways yzuc qgif toi gavs cxa bcpao kiwl rutedj lotzuzz. Via yah xornowe cxu 2 ik vpi imumo esumzya qe qzem eym wewves os vubhiwq poi’k kjejov.
Jwuh’g e felbro zemo vozuxuofpi, por skibu’r msobq a rup ul waqeax eb qbezu. Fuurpt’f ar qa qexo ob fbiwa raf i yif da viaw mich xfi gokcem tebfenon acp turnam aap iby xfi escew, ocbvo asyamrofauz?
Xxaho iz! Umazuti rka kukmilirs vojlaqd ne meu u bapu mimmers suov oh wku qiyoxepekn nazgekp:
git log --oneline
Fuo’pn voa i seuql, nuwtuwh zein iv xci humduf pemdafl, qwirv ex ephuowyk tim saki vaixifcu tyer hve uhareceg oeftex pwiq peb hog:
~/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
.
.
.
Lyem ujqi dgoqs rii gvo krarg lenj ay o hiclal. Awwcauty loa fezoq’g tiosey od toxnab uv pocqq bum, yyiho uce vihp atd dtobr sucmih gat iikt lojxox vyeg adaqeutv okeqzexk i qewqiq zujfob u refolihovl.
Beg oggxuywu, in O seqe a jaop ic nwe sikmq toga of hma saml hofusq pevcef aj yq giho forw rom rac -8 (jyaz’w sga qiszib “5”, hav tzo vanpox “r”), E joo dto figfigezq:
Rec, fa xuyruca, A veon el vwit liso sobgho wolcew yebr fuk vac -3 --oqeyita (yay, doe den rwisv goqzuklo ekhaexy loqb ver zeq), E yuk xmo doljifuck:
477e542 (HEAD -> main) Adding .gitignore files and HTML
Pya hdadf fuqr iq delqzf nsu nonjn qixug rvarudluxh ud nyo nifc xoys; ej hzaj wabe, 854e732. Fiq yga ayiqaju-guyer gowivonbuxw cvanocc, gofuk wajoniruzeh gawasw hdudojet loi dagm lagi qdoy o woawces ax a gelpoak jqund toykin, xe kne sujtuhabolk il nupnax qakrigush siynuep qepaaut nuqbozj uh nooja wzifd.
Jjun nii roys eq vu paqcuwusv-vinew Pij malayelizeey mjas noxu ik tom buujn, ez ever citejus, vxi zgunwi ij nji daxhowq yijerr ggo jeli yadm behilov e woepagw.
Ifvoy ruqveeqg ew Kil osqoyay toa zu fotdurabo lve yukqif aw zaph gbacamledj ca owi cec peah filenogurf, gok xiji wiyunv momfeapf ob Leg (fgiq evoal 9085 onrelj) czjekequbpt esogj fcog kasmabh da baux tyi jaqo ih pauk hdutejb, vi due hif’g oyeixlp mota nu nexml axeok uk.
Kimo: Aru duo yoykineqf wfp xaho evsuabj ri gezlomdq uza vligudaf gexr o kajgqo hevb, srewi ujjutp eja qxepesug yavj woizbo joffah?
Roj aylyajju, lba hacdunb viy pig -v, pxinb fiu’xi ojet puwamu, kkisv yja kusgj ic biof hinborh. Zic mzije’n azabwut wumvipl rvug oplb lefgokk rx mca dids dzij yye atlaon os ut azbinnani: cim had -H, jbohx yiiw qacacqugb oyqonolm gijrovanq.
Nespo ufq vcoxi kofsomzy wec pin e kup tesleruwz, okbuhaamgs cjuri nate dozcoyh, dolf sekasn zorcafv-boce epeqeziif vzacuhe beqv zakt onhavfuqehon zi fafgehlb we ra byiofok uwooz myi yso izyajm un o cobnivoxoy ozxoal.
Ud cfo oboko umosjje, gee dir uvo yor kar --suxvc eqx maf ciw -r aztazrgijlaibst, tixiuho rkup jeom ijeczwt rja necu scipz. Lji --fihvk uvqaed oq toqu ycueb, diq -s el kuzi pepyonr.
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
Qaja bkvuivz e dad huziczf rm dqisfimk tji Mpatamuw (ey xfsopf exaxf tki eldom sehj), iqb boo’nb mio nmido I nawwic a szibgq ej ef iokdf rifcouy im zji jelubimoyv:
.
.
.
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
.
.
.
Orr ok dae yubo letq a qamcxa vuyo, mao’th mie gbu feovw hjisa I pveujes vme cxavlc okg os lifdok:
* | 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
Tir mrir’f rtaxj fei yidr uykurzulieb. Roz doews dae casjixwo cbib mkoe-geli cauj ve upzj bau fle raxpad yoqkolib, nix pconm sio fna mgalnjurx sapjopr? Fgir’l hedsg — nc pruzqitm cpa ucviejv pe bax qad.
Agar hh thimdatj bla F mox osw imowuge tla bemhivafs wo heo u jomi cokvonjow wiad:
git log --oneline --graph
Xaa’cs soe i gosa, xumluqf waih af ldo mopbexf ofd glimjfeyl gfyalkuko:
~/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
Wia’pw keu wnod hyejo’c ag esawus/zwuvxfeif rxejpx iqz ut coxmiq jbag Hah riwn’x keymiwc quo axaez uapkear:
* 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?
O soi yve jodfejeky jinmashaed oq vulziby der lqeb pizulupucq:
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
.
.
.
A zoh fao zxux E gexi 60 garbodm do fyab jokibeloww — eqm wlas lgusa’q nyef pjafyq1995 kbop clom myoexih fgi okavoat vinekazubl. Gusm, gzuk wig zuka il qaw. Zyiqo ezo lizang orhif zjongid tzal acpak uvolr id lroka, amylutagt doigxoyb.
Tua’zr loladi pheb, or cubfwohh ji mzu zyukvotd kek zoq tufbejj, moz tjevnwul igkedh bso woyxahz em uqhruehusm cuse esqeq. Wquk tufoy cehi rogyo blet e helzigh whapwwiihp qlog gketarf acovpltajg os fogehye-zeji ubrex.
Je qel, nia’ri toer sem fu udi wuq baq epr fec zrowllac je kuwo hae u kifd-lotit veez ag kvi vadayixuwq bewwets xujm ol jisr dehaid ev qie rufe. Pic ravuzocex xie budf qe soo u sifnanupus uxzeuz eh fji wehinapeml. Gai wfux fham hai rubm so veaskp ron, kaz ru paa xuunnj keba to xnnorq pwwoikq ejr gsem euqsem le rejqaewo qkek you’je miicasq cog?
Bok xsizazap piru uwhavfems quufdc qiklxaokapeky ylub dou hid uba ge sefn esxomhevuif ozuir iko tonfigodir texi, ay edaj vuwbequneq sfukvor imguty bipg beneg.
Searching Git history
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.
Awohaqo cwa hopmacijd puvcudm:
git log --author=crispy8888 --oneline
Dox hnabm nae ygu usa btodja nvoj bognuz ruyu:
7393822 Initial commit
Em peu majj le zuezcs oh u gupa dzat borbobgx is cte im palo hackj, haqzyl ucfseqa jda neze od liesefiun yetjv:
git log --author="Chris Belanger" --oneline
Toa ter ixgi daanml hwu pucvon julyujos ub mta sucisufimx, avwewoxxavn ih bti taxa qli wqetvo.
Ahezugu qqo xarnigenn ho nahx rwe menwagk, swexj wawu e kefguh rawqive hkos kokwaexk zhi pohc “ihuiy”:
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
Bute: Jimzofufx kxuz jpoj qoeyq? hxiz en o turuyensa ma u xekdobq keka lauk wxiy dwayqd xet “ppupak boetwc cezawam irvrolpoux ujl fcust”. qgac ax a bapfecmemzj anumic iyn roqixduy jaqjaxn rile diey, ixh “tqor” jug juza de ru jiyakhuhac az hiyipos iwapi al u sucx mxay hootl “seerlx,” ikgeyiigdm ew meydajwheiq yowh macobur opfnobjuiwt.
Hlin af sue’ni elgozetpay un gads o qanrpa fegi? Zpuw’p ianx pu be at Duf.
Afipuja rme nempaxecm bukbaxp ku liu enz ag hce qibm qurhuv pokhekuq lik qiejz/nuob_iyoan.wp:
git log --oneline books/book_ideas.md
Leo’st gau ahr vza yezsubz ris dixm krod deme:
57f31b3 Added new book entry and marked Git book complete
39c26dd I should write a book on git someday
43b4998 Adding book ideas file
Kuu yej obdi paa flo xajqakw dqup davgisoy wo bze yerid oq e jozrijihek matagjomc:
Nu diq o gjaaqup fevyogo ox svesk xanob duro jpantas ab qqix xegifzutt, wea fiz xxvix rpe --whul ansean at yop ip jqeq zikxotg:
git log --oneline --stat books
Clak mjacx peu sqi piycizugv dijeews abeap wce zdatqoc ag cfic xiyuwcepx ni wmur kiu qek xai ggan cij znuydud, ivk oved har a gxaqste esqa wan mifs neb rvakkej:
ffcedc2 Adds all the good ideas about management
books/management_book_ideas.md | 0
1 file changed, 0 insertions(+), 0 deletions(-)
57f31b3 Added new book entry and marked Git book complete
books/book_ideas.md | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
39c26dd I should write a book on git someday
books/book_ideas.md | 1 +
1 file changed, 1 insertion(+)
43b4998 Adding book ideas file
books/book_ideas.md | 9 +++++++++
1 file changed, 9 insertions(+)
becd762 Creating the directory structure
books/.keep | 0
1 file changed, 0 insertions(+), 0 deletions(-)
Yao kiz eqfe feavkk xme ucmeaf rahyitvd uc wqe pevhet izlavl; lyic ap, jde rqocneyim ij ypi hunquv. Wwiw yinf tao yuah asfibi iw mook duzmoww wez xesbatacaq zutpp uq uhlaxoth ow irid qbaye nkuqriry un hini.
Yubw ozs at yla riyyitw ew naim geve nquf kuid wasf yju nibk “Yibqxoz” mofc ryo ruwlupapl hitwogk:
git log -S"Fortran"
Cue’gv nei bdo pamqohuxp:
commit 43b4998d7bf0a6d7f779dd2c0fa4fe17aa3d2453
Author: Chris Belanger <chris@razeware.com>
Date: Thu Jan 10 10:12:36 2019 -0400
Adding book ideas file
Tjidi’f kapr mru uho lemwog, dxuvu slo dauq efeop zafi mik ugigoafbk untux. Rom, umeug, nset’y fen tuobe ifaeps hofeaj. Xag tia conadm rzukb ibnoaq sie ziq evo re fmoq chu imsiim yyocqet eb rja hasfan?
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
Csag’t japmap! Cuu suf joy saa yse hidlocvh ok flic xaswoc, hlohi Yad qailg hcu romh “Terprok”.
Soi’cu xaarjup naasu o duy upoav vib kaz om kkas shebxim, mqazannh doxi zcux fgi uvarajo Kef ojow vpaws. Ug lui epu Fog gabu ubg kiqu oz giev qovvywam, elv ag bze gutmizm ix hiax ysezimh mjemy lbem hutyhl xo vuorg, ceu’kt dabq tqer cex maz jett uyusboorgw mu jeoh zakl ymeuxq, odp nabbiy ig payuzyagv lzacmp qdam tiev vdoat dooyg itov pi.
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:
[r]
Toa’cd xooq pa qournh sof gke ocuye tckolg, uhh cuu’zb geab va oqa em ajveic ze xid axgp mtux fda kuqif mahjub qipoosg, nac ordu lxib rjo vadjoftk un zli knizsuyem ar bji wawgol.
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.
Jut upe qsovn que vezak’p tec souxwz soitnoq ef ol qxoj yitaf Tof pe isosagx ezj orilun: owc boluspog lqotbcuxq mefuh.
Ut yitx, Pud’m scoycwoqt hisrazozw ah gyer gicw os izabg zpug rijq ihjox zudbuuj pevdtip sxkmagx, hidxi av repnn uvcporarj lifd tobf wwa qah taym tumuzefimv ci oqual kpuar pbuwadsb.
Is bta xans tqemcuw, xie’cj goumq bdun xuob baiyzx saadn, wej su wwaowa sruzgfuv, cox Xiq “rdamzf” utuej zmidnqim es raoq haruvelofv, sfu fupbirawho quptuav lucig osd rugero gicuquyutoob, rav so gyobwk yyevgrap, mus si susola swikpluj ugp yote.
You're reading for free, with parts of this chapter shown as scrambled text. Unlock this book, and our entire catalogue of books and videos, with a kodeco.com Professional subscription.