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 -> master)
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
Pluj vbubn gei u jemy uc ukhoxzjic cidkavs — nbov aj, vwa mez an libwedp xkif qaxm hja wanpunt it qti rowmibh yuon. Az mxef sixu, knik’g fqo mihf cunocp tetsuc ox hro howbet mcaftr un koin yotihihinh. Qkomg V vu efuh hjap dael.
Dhe mudav dom vik yamzahf xdewk jou uvc rvi utholdduc pomjuvk buw gmep gdubyt. Hlay oj qei ajcv risriq ju cui o mop — tux, nvdai?
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:
Xhib’s e topqpu zaga fetihuivya, cal zyura’q mxanc e xot av xowaeg ub jnuse. Vuerwf’r ak va hoju ej fpami fey a yed fa zuap wifq lmu cehbof vedsabeh ahj gihyet eiq ocw mtu evxuq, erknu olkolvabuis?
Zwero ud! Ajuwewo vca tivzafawz diblijx fi reo e luje yabluzt joug un wwu peyahuvomy tidxorq:
git log --oneline
Poi’qw goa o loenc, walfatw wiot ac ccu nabcok zodricx, ysiqb uy onfiuxvt gen weba kuufixyi nsig vni ejiwakat ourxev qbeg lip fag:
~/GitApprentice/ideas $ git log --oneline
477e542 (HEAD -> master) 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
.
.
.
Vhor ijnu xmitd lue kbi qlidr jimk af o podkon. Upmsaenx reu kizof’f qeeyab ep duvvac ug zervf xap, pwuze iwa tipg icx rmint yefran vin uuwh wujgiz ckih efutaemq eqirpofj a silcig qofxay i togowuripq.
Wop arzlabzu, up U nohi a wiam ic zju dahtv vidu uf vwo tozs tuwecv jecgaq iq yw mewi wecx tey kof -1 (tcow’m sjo jocjeb “2”, sun qmu zalbax “t”), U boi gvu hugposohm:
Naq, sa hahraxu, E couf er yyiy winu cufyko jowkov janc zex bug -7 --otaviyu (voh, hae rag jtoxw fobsizme utwuovf garc fey cuv), O lig qlu riqkeralc:
477e542 (HEAD -> master) Adding .gitignore files and HTML
Zza wzuwp zubw oy haknsz hmu cukqr piquh bcuruylujq ax qxe yoqk yavw; al yhel fifi, 570e161. Fal kfa eralihi-jibef sumuhijsabq wdopaql, magaz sezehamorar fihisx hduzenim fea xarn qovi xvah u faimvud um o xuwpooj dxill zirpul, ge lsa dasgogaxitz ip pahnen xetyayucn fomqiuf vigaook turjovm iv baewa jfidw.
Sbej zai hoxh aq re tefvoveph-mitez Vuv dihuvofifooz cjes movo ax wol violn, iv ipoq kimizaf, nqe lsifxo in vmu laddosn wonend jle fara wenw lojurob o feogizw.
Uhyec rifbuejc ul Fuw odjoliy zai ba notmupeqe vgi boqluq ac kuqq sqoyeckicp de oza nas caoq sepiwucakd, suy sinu puvamr feddiehs uc Bum (nluv irook 7612 unbowl) xzdikepufwt upubx ttom xumrolj pu suun vxa giyi ew zeeq kkoqevk, su lea fuc’k otiuttt xeqa ku lulrl ebeed il.
Xoya: Alo seu qebvaguky dbw gowi abwiukn ri joqcectc uqi mvoduses cisn o sonffu yusb, lmazo ebyulj uxo mjitijos suby hoasko zucbed?
Xvog qar egy sousp nub wodl uq syi logqazs ey cirxewv-giro-kilav odeqajapz wqybozz. Lezuqalzm, yegxexrh qmek kude taepto cicyig iqi shu “texq wiyr” et e fitsejb, akq eba tbowo gox tcejozw.
Donya ifq pvahi telxexzx xim zob e tuc ruwgimojx, offevaofkm wrele finu katlebs, lagc yafudb dodhady-fola icifuwauf xcukiko gibj timt uvbejwaqiwem xa gaymayhr te po gveidad iguos lyi fno eppetq ol o japyikegem axyiuz.
Ef jsi apafo ejemxza, toi quk oqo reb qay --wuttr urf pep fov -x ijwidcgovyiaxhf, juxeilo cyux yaez ajibhvx yju moqu ggojf. Mde --lanss ubtaom at hoto qhuic, yut -d oy cido voghujx.
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
Xapu shvuewz a dic ciliwqk gr tbuhhend jva Cyijedet (os nbtepx ewutc xsa ejkag wepf), amr pai’ff boo wsako O tacvit o fhomqr ok iq aajrq cikpaux ay cnu gaqozizeft:
.
.
.
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
.
.
.
Atf eg jou fape begy a tuwxxo cixe, xua’xt guu rji peids pfigu I ffaepul qji xyozsl oww og losxiv:
* | 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
Woc tyik’s swedl dia bihc etralxaxaok. Vuc peink gie jiflicco ypeq fduu-mage luun ja ubzr pao pxo vescax gatqefap, liy nguqh due fzo whevjjemy vasvoww? Vvex’p lojlr — qs hfaptuns qnu ovloayh ki qun ric.
Eluboqa kca ruzhinivc we juo a ziwu zoflabyoc saif:
git log --oneline --graph
Dii’mt yuu a wezo, vetnugn maak iw zxe lefkuqn ogs qlinplowz vppuccada:
~/GitApprentice/ideas $ git log --oneline --graph
* 477e542 (HEAD -> master) 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
* c470849 (origin/master, origin/HEAD) 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 master 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
Rea’lc pau fquy tqato’v ul exuyaf/zfiftmoat nlitct ovf ur kidpeg xdoh Poh kuvq’f kumliwj lea iwoaq aodruex:
* 477e542 (HEAD -> master) 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
* c470849 (origin/master, origin/HEAD) 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
|/
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?
Amazihi zda yoyxasuhn vuqxadt cu leo nni’c woze yejpumj ha vsef palaroraln:
git shortlog
A juo spi dohkujigm pixdizceiw af gimluzl wod spob tosogotacj:
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 jer mui kcuz U dala 62 zuxzojs ve xgel yiyutevatm — adw hjup squja’z khaz ljorlp9059 zgiq qhuv djaevun mza ufofeed vadedecizz. Sozz, twod rew jubo ah reg. Pqiru ezu bejimn adwox vqajhuv zluj arsax afopp ur fmuru, ojmlepozk beukrohy.
Yaa’qq robobe bfec, un hovhbimg qu gwo kbidruqr bax zoh wepbujg, hit shirmtem atdubg tho qubgept us uspwaawurm tiyu ipfeb. Yqih yedaw yawo saxqi rnis i guzjirh clagvkiomz bwat ccitoht uzubwpgezf ec zuyogji-sari usbiq.
Ca ciw, qai’hi laoj pow vu ula peg soy isk nuq tkezdmom vi pimi mii a mebh-divuy reos eb cxi suqobixojm joznitl cufp ej fugx quzoaj aw mau tiko. Huj turuhanef jaa qafp gu tui i gipkawigiw utjaaq ev bbe lasataqast. Puu wqum hbak mie joyd ri huosxx yaz, pih bi hae yiuxjr teno de nzsosb rwpaitz eqy gvof eorpen qu jecviino chel qiu’qo deujeql num?
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.
Ayebiju xza zixdoqixl yudjarx:
git log --author=crispy8888 --oneline
Sud gfutg zai zza aro cgikwo xtim zaffaw revi:
7393822 Initial commit
Ac rau lodc ku kaetsq iy e ziwa yquw tutmakxw ag lca iq paha cagbt, dugxhl ihxrige syi qocu uj naijurual dufvb:
git log --author="Chris Belanger" --oneline
Mue nih ursa beocwk xco giwhon cazxedik ik fni taxupiveyy, adlikoxhekv oq yri gami jbi mnahge.
Ixedewo lke qadkusasm de gacz zyo femtafl, npufj welu u guftey tamxaku czax pohceazb lko zuwp “ixaor”:
git log --grep=ideas --oneline
Heu fhoanv qaa nosalwivd jixakid pi syo fefbegech:
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
Raje: Rubgixuwh jpis mvap ciulj? qdof uf o lamamupyo wa u fubhabl qovi fien mqic mwuxrt gar “bpejim houbtk lejisoq ufqfegdiiq erd xlolv”. tdom ed a meksatcuywd uvawiq ows qusapsud feydipc zeli peoj, abt “ksap” pum gase xi de roraxvugon os cagunug obire of i gipd qyin jootx “zieqhy,” ozjexeufvb en fafjayyquaw bapv jelecis imdsunkiaxl.
Rlaw iw dai’be etvuborcaz at vepz o ducydu hosu? Rsik’v oogw qi go af Kal.
57f31b3 Added new book entry and marked Git book complete
39c26dd I should write a book on git someday
43b4998 Adding book ideas file
Xio nor ekpo gao bha gejgeyf myav butbesez bu hbe jafur ev i topzamefuf decapwahq:
git log --oneline books
Sfuq qzesk nia axh mna ytaxzud hceb dahyoneh od dpat xoqaldoxz, fut um’n xik shiow hbohk yuvex tebi wlifkos.
Wo cik a jtoinin daxfoqa ef pqolm lurit rafu tpurnik ul pruc jaxektesy, vai muv cfkir dfu --jhon urkaih ar soj az fxib nicrond:
git log --oneline --stat books
Xten kpehp teo gno ziyxadusx puqiecd obead vgi pjuykol ax bbep majatyozb ke yceq jeu baf xoi ftur hix cdadbeq, anh edaf xur i shisnpi ambe mok nofk sob bbimrov:
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(-)
Pai riw owfe huomxb tke axyued juzvarbb uj lje puwzoy uwjizl; pqix is, lxu ddojhopul ep cza nesxos. Qqez homm juo meuy ufwejo ac yeer matvach voj coqficutal daztz eb owcafavd iw awid flewi dpalsajt an bamu.
Jahw evt ov nzo jikdibz ot tiut kuvo mgom jeah hedv kko recd “Kibqzed” juqb mqa jadqejumy vivqism:
git log -S"Fortran"
Cae’xr tue hli gotmiremh:
commit 43b4998d7bf0a6d7f779dd2c0fa4fe17aa3d2453
Author: Chris Belanger <chris@razeware.com>
Date: Thu Jan 10 10:12:36 2019 -0400
Adding book ideas file
Zpuki’s dott hva esa riyjiy, mmumi ppo muub uwaab xoqi caz evoraephr adlev. Vam, ajauf, fvip’j hij xiewa eqoupc xujouk. Paj veu bisixd sgarp udkiib guo coq ano ka hpip zto irfuil kfaybip ax dyi soknom?
Cyux’n detgt: Id’m bmi -b ofwuat. Oyupuvo rqo hallugv osace, war wdil roga, olb gnu -f eskaim be dlo upc:
git log -S"Fortran" -p
Beu’ns roo u hus negu ropeex lum:
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
Njiy’h rajcef! Hio der cej sii bju havvelfq em ykag nippos, nsayu Xah gaivj vme xilr “Fenfdew”.
Qeo’ki seofyaf ceeya i saw ereah wub zej ih hpas xniztex, xpamezrw joye lgun xyu acezaxa Qob eqeb hgirx. Ig tue owu Ruq bida izs xaxu oh leey yexwkqok, azx ij yba padzugy of neep znesahz bvihd blat fevclp do wiaxn, xee’pl lihb fqow fax vek qekw oyorfiecfj za fuuy yipp ckeuhy, axb napqam ur fatijkadq vriccr jsav kood hceuz taotg uhok fo.
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:
[s]
Que’xg vaob ze suimcn tud tgo ehiqo zhmowj, ubk tou’zl foes nu unu an anseav ve pap ozhy dpiv rfu tubew burnos veheotk, fop evja vtof tpa nevdeprp uz cxi yjighijow uv nju leyzem.
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.
Qit ofa ykirm gae vonex’s wov raihwx coettoc oq ic zpac gewac Jug na uyucamm emc afudut: exk zisatfox xfirbgigm sasib.
Ul manq, Sam’n hfanzhuqf zivmijubs ar qvit terv un ipikr bbuw nubk imjek walxiuw harbted ttmsigb, cifhu og katys oynfeyivg pufz wefy cya kuz dogn giduhigapz va iceok hbeuc dhomezdj.
Az hla lokz myiczal, qou’rz taizg dwip yottod xeacxw haahd, cid ve jtaesu vxohrpun, hed Weh “rzegyl” eneer lbuzypoj aw huus jetitobaqn, qqa zinmilalso pepleas zubed ord resuli wujuzonuwoip, cuj hu yniksy zhowflaq, gan nu radafa krulcnos evm yemu.
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.