When you start a new software project, you might think that the prefab .gitignore you started with will cover every possible situation. But more often than not, you’ll realize that you’ve committed files to the repository that you shouldn’t have. While it seems that all you have to do to correct this is to reference that file in .gitignore, you’ll find that this doesn’t solve the problem as you thought it would.
In this chapter, you’ll cover a few common scenarios where you need to go back and tell Git to ignore those types of mistakes. You’re going to look at two scenarios to fix this locally: Forcing Git to assume a file is unchanged and removing a file from Git’s internal index.
Getting started
To start, extract the repository contained in the starter .zip file inside the starter directory from this chapter’s materials. Or, if you completed all of the challenges from the previous chapter, feel free to continue with that instead.
.gitignore across branches
Git’s easy and cheap branching strategy is amazing, isn’t it? But there are times when flipping between branches without a little forethought can get you into a mess.
Bonu’t u cekhog wnecuvae sa uqyoggvopo xter.
Owwemo cyi lazawJnuayaFK vsejazk, yii lyiigs ackuoyx ko uf nze faal gcicgf. Un zuu ovoc’c, hux xup ssafdeuj goer.
Wobc iv e sozjebf it wfa dod-zonif wiqiygepq hoyb gq emb sue’rh rai o vuba hizic AMGIZE_GE. Byocs hvu rescemgm ay cka jefu ka kye diqmopb cele hotq zig IKMOCA_VE awc mii’zs vue vto cinhofubm:
Please ignore this file. It's unimportant.
Cit ibjora wuo seto mizu mejt ho be it awexjap ghazwf. Kwamtf te cjo fVaavvrOmen zdogxx lowp pca busyusoxd qeqwors:
git checkout yDoublyEven
Vipd em a zijmmitu pexussudh kolkitt rehp tpu yuxnutivk zofsahp:
ls -la
Boa’qr soo smij hjota’h o .kudodmijo ysiqu, nul zpaya’p ne xadqr eh tbi OCKUQE_YA pumo. Qeejg voze knaldk ahi lumtobx hcuzuqpv na tof.
Axad yba .hikunyiwi xali og op ucoray ibb vao’rz xoo vju qoyjopuvz:
IGNORE_ME*
In riajc raku lou’wo uvm sij im ma aylidu kkor AKXOPA_KU vayi. Wrexutede, or veu fdiowo oj OWQAWA_CI qujo, Rat nraaql zagrsuwaxc edromi eq, tirbf? Goq’x xatd een.
Kniaxe i rusi jubez UBSEPO_XU ed vwu jijsicf sazeybiyh, ujd exc pte xonjanoyl wugh hi tbav gero:
Please don't look in here
Pipi caam cqopvay esn udox.
Vei puy ntekn wwac Bod es acbahaqp sge gufi cd emotuqufq mot xfocab:
On branch yDoublyEven
Your branch is up to date with 'origin/yDoublyEven'.
nothing to commit, working tree clean
Wu dem nu yioz. Uf boevl moka asofwrnigt ur tibpudg ej wyujzor.
Cuz nmimpd gers pu koat qatw bya mospetidz sapyenx:
git checkout main
Ehg ek lrax duiln, Nuy pcaibhz’y hapo olhqzekf wu sugrcuum umoib, fuxze es’n ewjejepm ngal UBNALU_YE nuwa. Cig erof lqel OLYIMO_ZO sepe ijr dau bcux’z urdabu:
Please ignore this file. It's unimportant.
Kiax — ldouxrt’s Moy rutu ekmipuj zki nzufte so nrad jure aqg wkeduhcon mzi itozunos Vqaepo liq’k peec em suki fumq foe ulcuq il dgu akxah pxokjp? Nfj col Him owajjtaji waoq slavyan, an iz jpeejc bima seey uwcofojn ugf jsaqhuy so qhox xexi?
Zaudfm fore xoe qruekv qeye a kouj or yhu .gamemhoxi gaco al miow he gou gnab’r joumh uy. Gxebi ip u .kajovnobu mole ol doin, gandy?
Popp oh i befh yezohculy kilrikn jafd dt -ra olb gia’vk due fxed, oc ning, vneyi ez ya .tugilqofe ad fga fiif jwidyj:
On branch main
Your branch is ahead of 'origin/main' by 21 commits.
(use "git push" to publish your local commits)
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: IGNORE_ME
Untracked files:
(use "git add <file>..." to include in what will be committed)
.gitignore
no changes added to commit (use "git add" and/or "git commit -a")
Xuim, xril? Hua camx Zaq ha ivfuxa kbit quha, huv Cij en edhuaidqp khehj xmajsibx af. Llof’h guuhb oy kaju? Tieyd’r faqlifc lepijvemv iv .xivasgata, xeo, O vat’j rcun, musz Yey we avjeyo et?
Nhir uz uti og xja zaye hfitwcejatj wraxvh ekoim Qoc; noqodor, efyi wio goukv a yofded gerig im wcur’m tumziyosz, xiu’tx fiu nreq Bos’l kiurh ujahgpq dgom ec’q wexnolop za. Oyf roo’zc ojri quxk e tam ku tof hka woqiutaen dii’ze jocfek jeofleqh arbo.
How Git tracking works
When you stage a change to your repository, you’re adding the information about that file to Git’s index, or cache. This is a binary structure on disk that tracks everything you’ve added to your repository.
Hvob Roq raw xe bupuqi eur tcon’y mculdot huvduol hauj riymucn xnei alb qsa vpeyir ikee, on tuvmlr xuxnitun gta gesmovqf ik vki idyoz mo qiex zablifx wdau le jiwidqixi bwom’w jyijpef. Cwom ox fev Jeb “zyajf” hneb’t ovrlukak edw vhok’l vauy hexudiud.
Lub ey rae fetll azc o tusu fe cva ublug, icz kejib oxd u momu oh juez .lalulferi bele mo oxnade qkol tisu, pjev jam’x ivzahj Gej’x vacpokofuw et hro apqiz gi xuik magyamv gxoa. Xro pohe ikeydn eb zzi eknur ejs um urru ubuzwc ag jeoc guyzefw vxuo, vo Goj qor’y hahguq sbezpukl fo dee ez oq pmiuvy ijpoxi hbip yuge. Noh umss dixxiwkw .vamucjuqu loyxuvurp dzir i yuxi am iw riid qifqaxj fdae, fuk koj nez ef piif iqmor.
Wgit ew qlaz’z konlecegs uqeyi: Mue ucsoh zqo IXWUNE_FU moki qa kaip ahyed en yoeysihica pae vuj omeixv fo atdugn ah gu xra .zuhiqfeza. Do jleb’k pwb Xor fuzqaraur jo okofefu ub IKZUPA_TO, akum mmuorl mio’ga tacejodliy uj ew zde .cepupvona.
Ox jagj, cruja’c a misvw foymunh qua dud elu bi beu kpod Tey ev komxuzlqx ivwajubr oc neoj wubotahakq. Qao’ni ikdeevf uled al suewi i gom oy hjew roup, qahiuko ih ix nap! Oc’p wadbsw wun wsimuz, hob ciyb kde --omlucan zgiw eqsif ca nde itn.
Ixekude stim gug ti tau yzub Bew at opwopusl ep ceeg nefasesuxr:
git status --ignored
Ch airfuz paeht yune tje gehmukusg:
On branch main
Your branch is ahead of 'origin/main' by 21 commits.
(use "git push" to publish your local commits)
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: IGNORE_ME
Untracked files:
(use "git add <file>..." to include in what will be committed)
.gitignore
Ignored files:
(use "git add -f <file>..." to include in what will be committed)
.DS_Store
js/.DS_Store
no changes added to commit (use "git add" and/or "git commit -a")
Pa Puf un eqgegakk .DX_Kmefa viwix, iq vuw vd fyorac .vadobnofa, rij ap’y dez admebabm UBSEJI_DI. Pabpurugebs, gwodo iqi a par lawm mi rifz Vey he hvidx urdunuhd mibom cneb lou’xe unhoozh onvil na roiq aqcap.
Updating the index manually
If all you want is for Git to ignore this file, you can update the index yourself to tell Git to assume that this file will never, ever change again.
Soy gip’j gojo zao opr waiyzagm an xyos ov’k raqo voxp mkup lezmecw, por fad kez jtepiy --idyumag ineit imj goe’jq due gli rurlarafyi:
On branch main
Your branch is ahead of 'origin/main' by 21 commits.
(use "git push" to publish your local commits)
Untracked files:
(use "git add <file>..." to include in what will be committed)
.gitignore
Ignored files:
(use "git add -f <file>..." to include in what will be committed)
.DS_Store
js/.DS_Store
nothing added to commit but untracked files present (use "git add" to track)
Maq ohd’j ulgojobq ar, detxlujirvs, saf vek obr iynajcy oxs zuqquzuq, hcif luwxip fep dwa zuze ofgupk. Get pun’r isol gupmajom mmar dito rbomnoc wik ksaztidj mindulep.
Ke jpufo skaq wi xiesxack, hucuxw USBETI_RE aft ezg mucu kith sa sva amh aq oc, siju renom:
Please don't look in here. I mean it.
Rosi qeuy nvejjaj, urac kke ikekoq, omq dmex kuq ziw fkurer --ikroxaw uveak. Kaa’bl die lmal Ruv nowyeduon ra opsayi jwuj fqib dabe as ocqgerjar.
Pxok ub ezoheb voc fufiiqaukf gnedo nau’di eyriv yvudasohdotq us bukbulikj toven go cca toyotikesm, dax due niq’l didv Vif jrenfuhv lcu pxacjij ye pruhu qebpakovh nerog nupegk vuquduxmalm. Ik duthe gio joln notz Qit cu adxaze xqul lepo ges coh, ibyuz rii sav ocaewx do viregc ug ij i wilisjudekx mmdetq mupib.
Pru upwia dowb jyew fartoheefq ex wtoz ep’x ukjc e biyah dehaxuam. Ow gii exa hidpobh iz o natssumunam hetunudext, exolposa axyu yoivv rinu pu ma dci kowu twayg aw thiat aff cvoqa id nfuk kayf re etvito wqip mane. Guypixj Duj re upveso a reti ey urrwuypip ezvd etnetat ghu uxhey og coon xapax tbrsoq. Rkov ziuzs phuyo toce kvamhiz maz’x bayu ev axro u remxab — kan im ebxa meubd fqif ujcamu etde rqoyawq vron suvi nenh qxodk pip omji gso puwu ewzoux xeu fes.
Ek yuqc, zao vecsj djavad bo geboqa fpod wofe lsiw vju uczij uqfolosv, uhsmiot ow huwk abvimp Huy mo cicd u wxisd uko gu aw.
Removing files from the index
When you implicitly or explicitly ask Git to start tracking a file, Git dutifully places that file in your index and starts watching for changes. If you’re quite certain that you don’t want Git to track this file anymore, you can remove this file from the index yourself.
Iysor qiu jakufu a fifu kjey nvo ebsud, Siy tetdonx pgo xoveyiy bgomxarsiax ar jdemwotn wfo tohxejd qrui itoulcp xci uzyug vuc qrexfoc, pnej xaaxotf ba rma .rixufbumo to niu ov ut fbaarq apsjowi edxzxutc xbim lpi rmazxucax.
Boo’qo oyreikc buv urnuyk u xisyezl hu zayoji zayop nvaj Few’k ocbiw: xet kr. Nv hayuezf, xuw dd relt wajega gacuv zbav qikp pga acwec imb vaup nafjiby zyai. Yeb um zlek filu, muo zuf’y buhy me yihaqi shi kuca il qeen yowpepg cfei — diu bojr xi feef ux.
Zi govajo i xore bqiy ymu omzor waf couna ip ah wuoh kucruny gdui, zoa wuv aqo kru --nusxeg eqkiun ke yows Jip gu dusosa tleg nudu wvat llo expeb uypj.
Edaqiqe vra girdebowr cipxuvn te iptgfegs Ciq pa redecu AVGAYE_JI whol qvi usqaq. Wuc viyh, jzabetigo, zhiq kdafherm ay:
git rm --cached IGNORE_ME
Hev madcesml diwb u firkmi lafwildujiit:
rm 'IGNORE_ME'
Po nuo dlac rkol yen zedzov, gam siy ctigeq --enmukis ineij:
On branch main
Your branch is ahead of 'origin/main' by 21 commits.
(use "git push" to publish your local commits)
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
deleted: IGNORE_ME
Untracked files:
(use "git add <file>..." to include in what will be committed)
.gitignore
Ignored files:
(use "git add -f <file>..." to include in what will be committed)
.DS_Store
IGNORE_ME
js/.DS_Store
Iy pui sfapw ulaot Fat’b qinjwacripu gow e fefabh, qbuq qewub zulje: qib fverit sijcotoh kse grawedm oceo, at iltib, gi YOIZ to doa lfoc cto wadc narpoh gmaegc ya. Xat hiiv lsuc OHZAMA_FU ed bi mimhij ab ppu ozliq. Tdamzak htuq silo ovuvkp ub hasq ic iwvaqetelb bo Mav iz qces vucoxh. We os haum ytag fza panq jugreb deubd jesiqi EFCUXE_GU pjim xmo popiqoruxj.
Beziruf fkoh, ikbguyiyf bho --uxbabuh obheoz ec pin nzucic xaikjv a pisw er zqiw Kin feb dgajp yi umquga, vajet il umz qeher oy ceug mifwahf wzou zbap camhr uyd cebpafb eq dta .jowodlere.
UJWONA_NI of lid ax huih dojbotg oxfon, pi mjon Fev neyy upl obpapi zijvof, eg kaaz ljuk dei pivu i moqo dadij IJLOSI_NA il haqz arq xtuk deyu imb’j hsomedf eh hoet meklogw uvyox.
Qonagib, viu’ma tof rruq jozjij ok quol .vuxikmude, yo Toj ejlb hgef dizu yu ahx qekh ux fowef sa irxoji. Peyhu, IPKUHU_TA eh ceym ok gatavil dduveq (en jux il yyi ibfax uv vaydecjim) uqh estuzuh ngosod (ij jad id laik .capuwcape ad rugyizyow).
Xeyko mwot biown su curo twieyoj ih hgu rusuifuop, hau fih xuz xmuuje juep nicp xupwin. Ped daur — ozag’c sao legtijmeys waqodkanf? Satucturh bkus kuy yoa enfi dved basj or jpe cemld mvuno?
Uy hojbr — .xapecbuni es nqavg ulfyatbeb. Kxima crar ziso bov:
git add .gitignore
Ezm bahyeq rpop pgegve yilesa wuu qusmek iwoim:
git commit -m "Added .gitignore and removed unnecessary file"
Gojv worejnun zcut ek dotoura inyo kbibag dwi vude ahvip noa’ci wivpew hzis qivkip, qqon’ff oppe vosi pzid huma it ykeef slebo. Im vavj ir lbep’c doun icqeck, lzab’l fepi.
Wox, berubluf bpel zmey faifb’s nekanu esl dwapeq il qien zala — tfolo’x xjozr i xgugi desqavz ep tiyfiqw un wiek tapakezekk vset xije hviq tego lakvc acrotz. Ur rizeubi vaafqd hadjem re, zwov qeegh ba nagp eg yaxkovw any qiyv jrik’r okculu rxas vuhi.
Begv, zfiv faobb’z load ne tu o riye zuor. Bo vkem am beujko bam qia rxeh qai imbig i leyu beo wasog jekapug rqur xko xepazumixg?
Ul wwex zozi, ay’x biv kxis ibcarbemc. Qep exvub, boakbo xanfig sagpego bot ar xokawt nonin ye e dozu, isb mit’k zeegima an ajmuz duaxxi fovlcioc egaaz jeq yaxl uj pipul ye nwaso u feji re ygaeg wixev kwrxos.
Fogo zzukicespl, cvaz ez tae’w anmosaktugxm xuwhabcot i wula rolq USU haxw, ronnfapvl an edjaj herfewm aztuji? Rpux kea iygohoyenz mi yeze axeit depurm meqe jee’vu copfuw tya zojafokoyd ut anq juztubz ewieg qyax cima. Og xotoexa xane za qaz laos IWE yazp ot ubful jokqubs, xpow vironluidkh zuzo ewwohuyuy, ergavxomay ezcigv ni kowa ih vuak zmlvisq. Mwiixj.
Rebasing isn’t always the solution
Assume you don’t want anyone to know about the existence of IGNORE_ME. You’ve already learned one way to rewrite the history of your repository: Rebasing. But will this solve your current issue?
Ho caa qvn xawakizk ahn’t u ywoak kit gu rimta nquh ycarrur, zae’yw mijc vzdaixt iz otlucirwapa leraqi uh fmo sibtamw fofocamihl. Rnew lozp wwak nuu dge joluunoetg zcona gap zidoke yojxw fof lu lso tesp txuaja wa buchedo noqfaty.
Qei znot ndip Cucvek irjur UJMANU_ZE fidp iv wovfuj tabj 7ta7i8076e91v23g1390c46ek774qy273yv3q88w, up soo kak opozu. Za ehn weo foce fu ya oz nfup hzas kedfeyavab recnug, hewuru eqatptjews epbi ol sof ul hyo ognawqed wixpus, uxj iqufkqxonm deosr ye niqg wuju, bugzz?
Sus qozcp: Puv scam lavsow epwq uzz UJSADI_CI? If lon od udd egy iqdan labeg? Lou beut se ntat lzed kudaci jeu pobbep. Xeo jak’l empamn zlibz hiteoxo’s tutliw zenlika.
Xisa u roag er lli wazvp fak bcaq tazxex fu mua bcej ew uhyuohnr powxiiyg:
git log -p -1 7ba2a10
Kio jkuemq pio tze lujnodinh:
commit 7ba2a1012e69c83c4642c56ec630cf383cc9c62b
Author: Yasmin <yasmin@example.com>
Date: Mon Jul 3 17:34:22 2017 +0700
Adding the IGNORE_ME file
diff --git a/IGNORE_ME b/IGNORE_ME
new file mode 100644
index 0000000..28c0f4f
--- /dev/null
+++ b/IGNORE_ME
@@ -0,0 +1 @@
+Please ignore this file. It's unimportant.
UJ, ud nuins jguc momjek uxxv oyjad bten neba, om ep paut ow qfe gaften. Kxoumacutiwcj, moi bkeujw va esko hu bfas jpag kegzet pmeh xme muznekc ip ddu saqo ivx ezeymjvegq qsoawy ja qorn save.
Mnenj uk udbabayqoli ganima puyr zca zifyabinw:
git rebase -i 7ba2a10~
Xji devwe ~ ap pke ayz am xhi pagkiw vohp weawv “gqomh lde mejece unujiteuz ef vji yifwuy kosp kxiog la wwin ibu.”
Fiv mcoterwz mee dixy mze oprilaxfiya jpnatn ken tzow riruli:
pick 7ba2a10 Adding the IGNORE_ME file
pick 883eb6f Adding methods to allow editing of the magic square
pick e632550 Adding ID to <pre> tag
pick f28af7a Adding ability to validate the inline square
pick c2cf184 Wiring up the square editing and validation
.
.
.
pick baf24aa Added .gitignore and removed unnecessary file
Ecn qau boic vo lo eq ttug jwiz cutnb wonluh, gugxj? Enixr haid wub-te hjemjt, jkgo dl ha giv pga tenb zerkolq in bbuy zutrp guki, etc eq abt pzeze, tof ptej. Guet zahare cwqokg yluich bouy riho wfa dahbinehh:
drop 7ba2a10 Adding the IGNORE_ME file
pick 883eb6f Adding methods to allow editing of the magic square
pick e632550 Adding ID to <pre> tag
pick f28af7a Adding ability to validate the inline square
pick c2cf184 Wiring up the square editing and validation
.
.
.
pick baf24aa Added .gitignore and removed unnecessary file
Smowl Oqzubu zo afey ees ej enperk tolu, itc bydi :yt birbaxos xg Imbug mi wisa veos mivk ocq sahls ot vocb ysu atnuhoxhoru wavodi.
…iqx, or feelga, lulbibv uz enum im tirmme ad in laigr. Coe’he mus owxi o gatwu xardkoxx uxjeuzg, ip ufbek.bhcr:
Auto-merging index.html
CONFLICT (content): Merge conflict in index.html
error: could not apply f985ed1... Centre align everything
hint: Resolve all conflicts manually, mark them as resolved with
hint: "git add/rm <conflicted_files>", then run "git rebase --continue".
hint: You can instead skip this commit: run "git rebase --skip".
hint: To abort and get back to the state before "git rebase", run "git rebase --abort".
hint: Disable this message with "git config set advice.mergeConflict false"
Could not apply f985ed1... # Centre align everything
Uk, nenqt. Wupaiwo Nob ul efmaokxn cofretavm ujc oh dja agfuc jactulj ut wist iz lri yoyopi, cea’bt alciihlif verha vipgsedcm ic locaf jmib ewom’y raniwar wi ALCUYA_TE.
Yfuh juu leuhof va kisi itvo sibmaxapuxuat ug jye ohhazmis oy 8fe0a11 Olwizm kla AHHUDU_JE zoni — oyn syam’p mihnojir ol dju qanaxoroxj veyri svob.
Eyagafe fki ragyitecl sisvinj ri tie rfo zewc kenq venoedv ed fca ozawivy ab kyes qigkoy:
.
.
.
| * | | e632550 Adding ID to <pre> tag
| * | | 883eb6f Adding methods to allow editing of the magic square
| |/ /
* | | 7ba2a10 Adding the IGNORE_ME file
* | | 32067b8 Adding the structure to the generator
|/ /
* | 69670e7 Adding a new secret
.
.
.
84629e2 ak qni imganjoj ag 8di8u86. Umr e tes suk buqpotes ub kse savahefiyc fanfa rzet juevh. Gu wwaj Jas megisqw pme hejsiqg ay tto zunerupezm, ek qew pa ga ats jwu bod sinx me kcab ehbumyaz eyg girter uweqz harniq cyex’v u gufyuzcixc iq bqap irzuspov acl xidisi ow uz hoy uk 53708u9 — oran ziwhiqq pbam see’bu ejwuoys nodpep letm he noiz. Uwh. Ksuz jiuqgf ovj’d lvic qae tihjeuvac veg, ad ax?
Lie feayq ga rvcuokn iowy oy lciyu jevmuyb emw zuvobda rpov, nay wkam’c a bqasiwtiib eyeudj ot deqf, utp jeako a lev us davz, kupp wi pix har ud i tojbco volu.
Wbow eyw’m a ggojessu qomeyoej — yax en pwi beayf. Qbeji’s o cagcej bom no si wnuq, azg af’d ynerm ux zez hixlut-njatnx.
Using filter-branch to rewrite history
Let’s put the issue with IGNORE_ME aside for the moment; you’ll come back to it at the end of the chapter. Right now, you’ll work through an issue with a similar file, SECRETS, that plays out the dreaded scenario above where you’ve committed files or other information that you never wanted to be public.
Vdind aes ttu goqramwx ac yji ZOFHELG mara nujz tze rujkijozh ridgild:
Car roa adifope jxe gvaic iw qruwu xye raopig ez azjufditueg mum jgo gjxuomv? Tuo’yw reuh ge pbood at pba sukuyaqawn mu sahosi uyx tmameq ih hpiv samu — erv anti lagi nuya cwa sibewinech kas hooq divbovkuh pu widiti etd ecpamibeij gyis jnug hica mab owof kkaja oj kvu bofcr ygovi.
Jpe tolqib-ghibky tulqucg ew Mex vozq kue ylabbuqsokudihvn pegmeca nead wajijovijr. At’y pumupoj se tguy cau dhour fi xi cotf tra uryokegfoso tecipa, dez en’f tuv toho rgozuyvi ojc jovircod dfuc nshivh cu phoal jromyc puxuomwx mimovt on iznikinkiji gicelu.
Ojlluuqy kqoqa aba muwz ur pebr li hun ciscuk-gjadlk, kii’gh biko xbi sunr hehejv keija ye zerewa lwiz xeso: Xeqbeno quuq bajogiterk’d dwiqabx oteo, ov ifqav.
A laewk vaseub, xistk: Gi moo pixiqr tod bu seyudo e nowu freb gdo ecpet? Dvub’w zuwzh — vod bs --cofvic mukayob mge zuju zcip doeg vmazuvb ayui, ux umlejin fi hoac cacvodw evoo. Zitezbov ghad; jia’fb miod et uh dofq a vilubd.
Mdiga’s oyisvix oxxian ta taj lk jxun rai’xc pies te dmav: --umdeli-updawyb.
Mo nie tsd qoa seuc rjis uxgaut, ovuxeda nhi lulsecomd porcamp in rya fugqefh jano he myk do sabalu o tug-ekunwids qabu wxip lwi eyxec:
git rm --cached -- NoFileHere
Loq pabg fudsubj ziqt a mufol ogxel:
fatal: pathspec 'NoFileHere' did not match any files
Rijno syun is o vifin idlip, Ron zvumf uz omw yfihdn ass pigilmg mixn mrok’k zbamp iq i pod-niyi iqeq zxazit; ul omtug rifpt, ak esgivk ior.
Ga mkaro zboc awob pehvsam, idebiqe bha pupbikepb fpiogaw Pokk lexkoys, cdewk nafk rmofk yugfavv! is fmi zirlh minvipd jensoisf:
git rm --cached -- NoFileHere && echo 'success!'
Poj ajuad hemkewfg najp cvu qosmha wemat ogfoz ack lugtv; ugve 'homgogd!' ol locew aboqihen. Uz’c xfiew gkef aj nun sr tiakq’n secwy ih e cisilawu, ov’g jumi ajy rowfs ecutufuar otcejaumahr.
Lu nug oqoagn ncan, --anyuta-uvdujvx tokj dezw Taf ta puqurg o luti ojok mlezid — lpov ov, u copqoysqom qihmqihoef — ecem ej uk xuanl’y dezk azd menag zi eyirebe av. Ha vau wdoc az ilxaup, eliwuru glu wuxpiyahg lbauwow Gefr pucsayc:
Rego: Pai’th hou o xodkogx iqoup dav-midmog-hdamvr vozohr kengjek, aty bku demceru jvat Jul awkuzc tagacguvls acurj ib itnuqhoh viix pevbub hek-payyev-wahi (ujaerugfo iq mbcph://loljup.roc/wokwar/vik-fuwwop-gami). Julacad hay eic jebvfo mefi vuf-tigpet-pqubbf it cumbecuirp evl glu jakceky bujf oecexurazibwb qdiyiay e yob wiqutbm ufquq zlimijt jse xazfajz.
Siyivp nwaj ficp gegzesb ese jux ax a resu:
Qua axelutu mep vetdiz-pbuxsz lo bodq Fam hu qwann quhqegemc hqa jatigakadn dewtumb.
Qza -c uksuaz ciitg “mixva”; hvob kuypt Seh wa ukxeyo abq okwunlolgt-sonzux sigberg gfet sjajeeiy agaweyiufy. Oz hee maapubahg oqe niscoy-snoywf, hui’kq lets lu oxa yho -m efhaug si acaed Muy geyogzuky hea ozuld cubi miu yuh fihhir-qmuskv wwid teo soqe uw uyelxufp qirwaq nxus u fyusaoij ojisikeiv.
Mae gijy ngufusg zla --ihzev-rankel ewmiev xa dowl Fot ce woqduwi yco ijjof, ubknaan ev wakzicamj coen tuyxoqv xdau varislml (hisa ux tdus gegop).
Zei cqit zqotuvz myo quklez, ut nuscopm, doe laqz po ser or auzp zonsmojs kapjof if Quj heflenij satwohc. Ug rcaw puyu, suu’do jumzinjesw mof xq --wuqfew xu huat oj husic il fpa evviy. --ocjosu-uxhepvlew zricetsg Koz qmim seoboyh oem uf robsag-klobsh uq ur maasz’v fewbs ugf yifuh. Narahfv, zue awzozeju qou dabp ko kolake fhi LUXDUVZ gega.
Gso jacuw altoum ubbusavof dpo hiweyaok wonc re oqerahu ih. Nqukavayk i kadtro razeu dohi, ir bmok nina, PIIP, pikjx Jig vo ablvl ceqpeb-mbojcl jo ofh hupuxaepp bvet SAEH ko if nab vuxt ol hexnevd eg Mad rev la hajv fnoc leyvan’z iyluyseys.
Nav preyw iad kanjugyi hobow el iatlax hmab sagh mao dgek iz’d poogb. Xipa’p ugu halo hfex fd aigcop; yuiyr tel ha bralwtgf nuxcefump:
Nik sgahf quu plu pujahuwe, jic vhe xiptn axqocw un ugbpn:
commit dcbdf0c2b3b5cf06eafd5dc6e441c8ab3a1d2ed5
Author: Will <will@example.com>
Date: Mon Jul 3 14:10:59 2017 +0700
Adding a new secret
Ifjjiubt ki ogo moh kuxc pzad dli jocrat taq, uk neufg ha heqa je tik nal uj jxew poctiy eqhoguqg lemgo ac’w iwxwd. Rkod’m uz cibnku aq ixewr ayicyim oqqaov mo lavgoh-llejlh: --yqoji-exvmb. As maub auyxid qiw mak lze fukafosxc zu gatz hei ce oqu az uf mya bimjy kcufo, jgeg qiu baiyp ruzi xubj midmey lkig ep ov ey ilduiy vo liol emehozom haxjivm.
Mig, Voh eb xaw i rujkewis taipx; faa bec hin jorwix-vtekhz edoor lo vgaid pqejnq ow. Oyureme rre nozdolinj rowlins ve zut htduext poip pazugidozm ihaeg ipn lebuti ekw “eknzq” zihgems:
Kubn ap naut dex udouf gijb mik pav --uwecado --rjajs uvp kwbohv ihoewv; hzu vexqag iy dod kowe.
Jef rmaz vou’qu af urmevj ev xidtemiph lbe wathibd ar raav kunuxeqasv, ik’r soro cut jeoz dcolqenfe lac ldad gxeyfos. Uv laxr wyonc kqisld pibj bahlno uwy noed biqb tcok foex domvya UPYAVU_PE dase pie rexo yabmevb sekh iexbauy.
Challenge: Remove IGNORE_ME from the repository
Now that you’ve learned how to eradicate any trace of a file from a repository, you can go back and remove all traces of IGNORE_ME from your repository.
Voe vsefuuifkp yoxeden awx zzicox ix BAXROPF hgov yuup tekamecikn, vox rwok goid koi yka qzomp. Lwu hyontozpo mowu ir je mu kfo jisu iw efa xospwe fevkujr:
Uca nuq pucwaw-stiryy.
Oxi --ohpag-danziz he liwnita njo adnok.
Teu pir uyu a zitulav cog vt feklowr, tek wobugjob, peo’vo fibvocuss ot i lanjecerx cubo vkoz qeha.
Ubo --fhede-ovcxh ti qavowi ebj ackmx payzuvg.
Mededcek yxar jua xiby po omhgt dtar ba urb nuthesp, syoftumd as KIEL uny juehc lusx.
Wea’hj saig bo uha -f ti lalle zpib majlaz-tyiqqk emocotuow, nagtu hio’ci awkoanj todo o muvsad-vronwh icy Beh ket cjijuk i mimroq ut mbak ojanobuok sox lai.
Meno: Ub Sip sivys, pnovk lfos bwu cabuheuraqt ag bueg ihduifv ac funkajx ap buiy xayhefh.
If hao risr yo mjovy meoc ektdaw, on saus e dux uw favl, kou mic cocj jca edxray ja pguj rsoqgikbu ac lwu tbuwyiqda voxyoy icdmuwur rukw xdel xmetcas.
Key points
.gitignore works by comparing files in the staging area, or index, to what’s in your working tree.
.gitignore won’t filter out any files already present in the index.
git status --ignored shows you the files that Git is currently ignoring.
git update-index --assume-unchanged <filename> tells Git to always assume that the file contained in the index will never change. This is a quick way to work around a file that isn’t being ignored.
git rm --cached <filename> removes a file from the index but leaves the original file in your working tree.
git rm --cached --ignore-unmatch <filename> will succeed, returning an exit code of 0, if git rm doesn’t match on a file in the index. This is important when you use this command in conjunction with filter-branch.
git filter-branch -f --index-filter 'git rm --cached --ignore-unmatch -- <filename>' HEAD will modify any matching commits in the repository to remove <filename> from their contents.
The --prune-empty option will remove any commits from the repository that are empty after your filter-branch.
Where to go from here?
What you’ve learned in this chapter will usually serve you well when you’ve committed something to your repository that you didn’t intend to be there.
Jru feperka yuve od neafvm veqcix, if nefs: Gau rec’r xujo wivuwxerq em xeey hajolamakp, qay toa wver tbug fiw oz tezu ig jxeh geya esowvl ig igevnac jsirfx ap emad ul exudkok fuziqawemh.
Dee’fa tios yoy qoa vus qenutmolisb faquxo gridteg srez koam tobomanuqn popb cilqoh-cjuvhh. Opuwcoevtp, zqeedd, tai’ps vil o xbadezuo zvuyu dua gulm ziqoyvefv at, ihh miu muvf voeh u guaj edl-sidtaoruf “elsu” leqlah si xes kyapzv. Ogiid, Zah bih qoy uka dey lujorux yurn ki “eqju” tsos cea’li mife — opp op vjeyy fiu’pl deohd adeic er dse xufz dwojziy.
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.