Git log 和 Git reflog 區別

雪花飄發表於2020-06-14

最近工作中涉及到 git loggit reflog 命令的使用,但是在使用時並不太清楚這兩命令的區別,於是開始了我的學習實踐之路。

  • git log 使用
    git log 檢視 commit 提交歷史,獲取內容已經進行倒序,可以使用 -n 引數來設定展示 commit 條數,使用引數 –pretty=oneline 來進行簡化展示。

git log和git reflog區別
如果想看到其他人在該分支上提交的最新的 commit ,需要先拉取遠端最新資訊下來才可檢視 git pull

  • git log 只能檢視當前分支下的 commit 資訊,檢視其它分支 commit 需要切換分支

git log和git reflog區別

  • 對於回退後的 commit 是無法通過 git log 來檢視的

git log和git reflog區別

git log和git reflog區別
回退後 commit 丟失,如果我反悔,又想找回對應 commit 的程式碼呢?git log 是無能為力了,但此時 git reflog 就派上用場了。

  • git reflog 檢視本地的 commit 變更歷史,並且 commit 是不區分在某個分支提交的,加上 -n 引數可限制返回記錄數目

git log和git reflog區別
利用 git reflog 命令檢視 commit 變更歷史,經常可以進行回退操作,或者可以進行恢復已經刪除的分支

git log和git reflog區別

git log和git reflog區別
哈哈,總結及實踐到此為止了。
前陣子同事用 devops 程式碼釋出平臺總是反饋拉到最新程式碼的 commit,但是打包出來的包還是以前程式碼的包,我就奇怪這怎麼可能呢!於是到釋出機上使用 git branch 發現是其他的分支,再 git reflog 一下,發現他們需要的 commit 其實更新下來了,卻被切換了,這一排查,找到問題所在,其實是另一個同事在程式碼裡的指令碼加了切換分支的指令碼。
哼,想讓我背鍋,不可能的!!!

本作品採用《CC 協議》,轉載必須註明作者和本文連結

雪花飄

相關文章