[{"data":1,"prerenderedAt":553},["ShallowReactive",2],{"blog-post-\u002Fgit-reflog":3},{"id":4,"title":5,"body":6,"date":541,"description":542,"draft":543,"extension":544,"image":545,"meta":546,"navigation":159,"path":547,"seo":548,"stem":549,"tags":550,"__hash__":552},"content_en\u002Fgit-reflog.md","Obscure Git commands: reflog",{"type":7,"value":8,"toc":538},"minimark",[9,14,18,21,28,50,59,62,93,104,107,110,347,350,356,483,489,494,508,527,534],[10,11,13],"h2",{"id":12},"reflog","Reflog",[15,16,17],"p",{},"I wanna explain the reflog command by going into a familar scenario.",[15,19,20],{},"What happens when you accidentaly delete a local branch or overwrite a\ncommit. For beginner and intermediate users like me, it can seem like there is a\nno way to recover.",[15,22,23,24,27],{},"Git has a less known command called ",[25,26,12],"code",{},".",[29,30,35],"pre",{"className":31,"code":32,"language":33,"meta":34,"style":34},"language-sh shiki shiki-themes github-dark","git reflog\n","sh","",[25,36,37],{"__ignoreMap":34},[38,39,42,46],"span",{"class":40,"line":41},"line",1,[38,43,45],{"class":44},"svObZ","git",[38,47,49],{"class":48},"sU2Wk"," reflog\n",[15,51,52,53,55,56,58],{},"git ",[25,54,12],{}," is a command that gives you access to a log of previous Git\noperations. The ",[25,57,12],{}," command is like a time machine view into your Git\nworkflow: it effectively gives you the history of everything that has changed\nHEAD, a special name that points to the commit that represents the current state\nof your local repository.",[15,60,61],{},"It even tracks changes that may not appear in the typical commit history:",[63,64,65,69,72,75,78,81,84,87,90],"ul",{},[66,67,68],"li",{},"Creating commits",[66,70,71],{},"Switching branches",[66,73,74],{},"Resetting branches",[66,76,77],{},"Amending commits",[66,79,80],{},"Merges and rebases",[66,82,83],{},"Reverting a commit",[66,85,86],{},"Stashing changes",[66,88,89],{},"Pulls and fetches",[66,91,92],{},"Force pushes",[15,94,95,96,99,100,103],{},"Think of the ",[25,97,98],{},"git reflog"," command as a Git's version of shell history. Its also\nsimilar to the ",[25,101,102],{},"history"," command in a way that, it shows only the logs that are\nhappened into your own, local session.",[15,105,106],{},"Now how is that relates to our disaster despair scenario?",[15,108,109],{},"Let's create a branch, create a file and commit that.",[29,111,113],{"className":31,"code":112,"language":33,"meta":34,"style":34},"$ git checkout -b big-feature\nSwitched to a new branch 'big-feature'\n\n$ git commit -m 'big-change'\n[big-feature a400869] big-change\n 1 file changed, 0 insertions(+), 0 deletions(-)\n create mode 100644 content\u002Fen\u002Fbiiiiiiiiiiiiiiiiiiiiiiiigggggg\n\n\n$ git checkout main\nSwitched to branch 'main'\n\n$ git branch -D big-feature\nDeleted branch big-feature (was a400869).\n\n\n$ git branch -v\n* main 8c76b1d update post\n",[25,114,115,133,154,161,177,184,227,242,247,252,264,276,281,295,315,320,325,337],{"__ignoreMap":34},[38,116,117,120,123,126,130],{"class":40,"line":41},[38,118,119],{"class":44},"$",[38,121,122],{"class":48}," git",[38,124,125],{"class":48}," checkout",[38,127,129],{"class":128},"sDLfK"," -b",[38,131,132],{"class":48}," big-feature\n",[38,134,136,139,142,145,148,151],{"class":40,"line":135},2,[38,137,138],{"class":44},"Switched",[38,140,141],{"class":48}," to",[38,143,144],{"class":48}," a",[38,146,147],{"class":48}," new",[38,149,150],{"class":48}," branch",[38,152,153],{"class":48}," 'big-feature'\n",[38,155,157],{"class":40,"line":156},3,[38,158,160],{"emptyLinePlaceholder":159},true,"\n",[38,162,164,166,168,171,174],{"class":40,"line":163},4,[38,165,119],{"class":44},[38,167,122],{"class":48},[38,169,170],{"class":48}," commit",[38,172,173],{"class":128}," -m",[38,175,176],{"class":48}," 'big-change'\n",[38,178,180],{"class":40,"line":179},5,[38,181,183],{"class":182},"s95oV","[big-feature a400869] big-change\n",[38,185,187,190,193,196,199,202,205,208,211,214,216,219,221,224],{"class":40,"line":186},6,[38,188,189],{"class":44}," 1",[38,191,192],{"class":48}," file",[38,194,195],{"class":48}," changed,",[38,197,198],{"class":128}," 0",[38,200,201],{"class":48}," insertions",[38,203,204],{"class":182},"(",[38,206,207],{"class":44},"+",[38,209,210],{"class":182},")",[38,212,213],{"class":48},",",[38,215,198],{"class":128},[38,217,218],{"class":48}," deletions",[38,220,204],{"class":182},[38,222,223],{"class":44},"-",[38,225,226],{"class":182},")\n",[38,228,230,233,236,239],{"class":40,"line":229},7,[38,231,232],{"class":44}," create",[38,234,235],{"class":48}," mode",[38,237,238],{"class":128}," 100644",[38,240,241],{"class":48}," content\u002Fen\u002Fbiiiiiiiiiiiiiiiiiiiiiiiigggggg\n",[38,243,245],{"class":40,"line":244},8,[38,246,160],{"emptyLinePlaceholder":159},[38,248,250],{"class":40,"line":249},9,[38,251,160],{"emptyLinePlaceholder":159},[38,253,255,257,259,261],{"class":40,"line":254},10,[38,256,119],{"class":44},[38,258,122],{"class":48},[38,260,125],{"class":48},[38,262,263],{"class":48}," main\n",[38,265,267,269,271,273],{"class":40,"line":266},11,[38,268,138],{"class":44},[38,270,141],{"class":48},[38,272,150],{"class":48},[38,274,275],{"class":48}," 'main'\n",[38,277,279],{"class":40,"line":278},12,[38,280,160],{"emptyLinePlaceholder":159},[38,282,284,286,288,290,293],{"class":40,"line":283},13,[38,285,119],{"class":44},[38,287,122],{"class":48},[38,289,150],{"class":48},[38,291,292],{"class":128}," -D",[38,294,132],{"class":48},[38,296,298,301,303,306,309,312],{"class":40,"line":297},14,[38,299,300],{"class":44},"Deleted",[38,302,150],{"class":48},[38,304,305],{"class":48}," big-feature",[38,307,308],{"class":182}," (was ",[38,310,311],{"class":48},"a400869",[38,313,314],{"class":182},").\n",[38,316,318],{"class":40,"line":317},15,[38,319,160],{"emptyLinePlaceholder":159},[38,321,323],{"class":40,"line":322},16,[38,324,160],{"emptyLinePlaceholder":159},[38,326,328,330,332,334],{"class":40,"line":327},17,[38,329,119],{"class":44},[38,331,122],{"class":48},[38,333,150],{"class":48},[38,335,336],{"class":128}," -v\n",[38,338,340,344],{"class":40,"line":339},18,[38,341,343],{"class":342},"snl16","*",[38,345,346],{"class":182}," main 8c76b1d update post\n",[15,348,349],{},"Oops... You get that? we lost our branch!",[15,351,352,353,355],{},"Let's see what ",[25,354,12],{}," has for us:",[29,357,359],{"className":31,"code":358,"language":33,"meta":34,"style":34},"git reflog\n\n8c76b1d (HEAD -> main, origin\u002Fmain) HEAD@{0}: checkout: moving from big-feature to main\na400869 HEAD@{1}: commit: big-change\n8c76b1d (HEAD -> main, origin\u002Fmain) HEAD@{2}: checkout: moving from main to big-feature\n8c76b1d (HEAD -> main, origin\u002Fmain) HEAD@{3}: commit: update post\n\n",[25,360,361,367,371,409,428,458],{"__ignoreMap":34},[38,362,363,365],{"class":40,"line":41},[38,364,45],{"class":44},[38,366,49],{"class":48},[38,368,369],{"class":40,"line":135},[38,370,160],{"emptyLinePlaceholder":159},[38,372,373,376,379,382,385,388,391,394,397,400,403,405,407],{"class":40,"line":156},[38,374,375],{"class":44},"8c76b1d",[38,377,378],{"class":182}," (HEAD -",[38,380,381],{"class":342},">",[38,383,384],{"class":48}," main,",[38,386,387],{"class":48}," origin\u002Fmain",[38,389,390],{"class":182},") HEAD@{",[38,392,393],{"class":44},"0}:",[38,395,396],{"class":48}," checkout:",[38,398,399],{"class":48}," moving",[38,401,402],{"class":48}," from",[38,404,305],{"class":48},[38,406,141],{"class":48},[38,408,263],{"class":48},[38,410,411,413,416,419,422,425],{"class":40,"line":163},[38,412,311],{"class":44},[38,414,415],{"class":48}," HEAD@{",[38,417,418],{"class":128},"1",[38,420,421],{"class":48},"}:",[38,423,424],{"class":48}," commit:",[38,426,427],{"class":48}," big-change\n",[38,429,430,432,434,436,438,440,442,445,447,449,451,454,456],{"class":40,"line":179},[38,431,375],{"class":44},[38,433,378],{"class":182},[38,435,381],{"class":342},[38,437,384],{"class":48},[38,439,387],{"class":48},[38,441,390],{"class":182},[38,443,444],{"class":44},"2}:",[38,446,396],{"class":48},[38,448,399],{"class":48},[38,450,402],{"class":48},[38,452,453],{"class":48}," main",[38,455,141],{"class":48},[38,457,132],{"class":48},[38,459,460,462,464,466,468,470,472,475,477,480],{"class":40,"line":186},[38,461,375],{"class":44},[38,463,378],{"class":182},[38,465,381],{"class":342},[38,467,384],{"class":48},[38,469,387],{"class":48},[38,471,390],{"class":182},[38,473,474],{"class":44},"3}:",[38,476,424],{"class":48},[38,478,479],{"class":48}," update",[38,481,482],{"class":48}," post\n",[484,485,486],"info",{},[15,487,488],{},"Everything in Git is checksummed before it is stored and is then referred to by\nthat checksum. However, Git usually displays only an abbreviated hash, often\n7–12 characters.",[15,490,491,492,27],{},"We can see that there is a log entry for a commit that moved the commit hash to\n",[25,493,311],{},[15,495,496,497,500,501,504,505,507],{},"Then, to get our ",[25,498,499],{},"big-change"," branch back, we simply use the ",[25,502,503],{},"git checkout -b","\ncommand to create a new ",[25,506,499],{}," branch with the commit hash as its most\nrecent commit:",[29,509,511],{"className":31,"code":510,"language":33,"meta":34,"style":34},"git checkout -b big-change a400869\n",[25,512,513],{"__ignoreMap":34},[38,514,515,517,519,521,524],{"class":40,"line":41},[38,516,45],{"class":44},[38,518,125],{"class":48},[38,520,129],{"class":128},[38,522,523],{"class":48}," big-change",[38,525,526],{"class":48}," a400869\n",[15,528,529,530,533],{},"Now, our ",[25,531,532],{},"big-feature"," branch is exactly where it was before. Cool.",[535,536,537],"style",{},"html pre.shiki code .svObZ, html code.shiki .svObZ{--shiki-default:#B392F0}html pre.shiki code .sU2Wk, html code.shiki .sU2Wk{--shiki-default:#9ECBFF}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html pre.shiki code .sDLfK, html code.shiki .sDLfK{--shiki-default:#79B8FF}html pre.shiki code .s95oV, html code.shiki .s95oV{--shiki-default:#E1E4E8}html pre.shiki code .snl16, html code.shiki .snl16{--shiki-default:#F97583}",{"title":34,"searchDepth":135,"depth":135,"links":539},[540],{"id":12,"depth":135,"text":13},"2026-07-05T00:00:00.000Z",null,false,"md","\u002Fblog-images\u002Fcows.webp",{"alt":34},"\u002Fgit-reflog",{"title":5,"description":542},"git-reflog",[551],"coding","u-2VT9SshNV5y1PpYLRA3tq7AyprDAME38szA8L9sJ0",1783292473946]