[Git] Git Reflog

less than 1 minute read

Git Reflog

  • Reflog
  • Reflog References
  • Rescuing Lost Commits

Reflog

  • Reflog is a record of when the tip of branches and other references were updated in the repository.
  • The logs are stored in the .git/logs/HEAD file
  • Limitation
    • Git only keeps the reflogs of the local repostiory
    • Git cleans the old entries after around 90 days by default
# see the logs
git reflog
# see git reflog show {reference}
git reflog show feat:reference

Reflog References

  • name@{qualifier}
# where HEAD was 2 moves ago
git checkout HEAD@{2} 
# git checkout HEAD~2 # 2 commits ago
# HEAD involves more than just commits(e.g. checkout)

# difference between current HEAD and HEAD 2 moves ago
git diff HEAD@{0} HEAD@{2}

# timestamp reference
git reflog show HEAD@{two.years.ago}
git reflog show HEAD@{one.year.ago}
git reflog show HEAD@{two.months.ago}
git reflog show HEAD@{one.month.ago}
git reflog show HEAD@{two.weeks.ago}
git reflog show HEAD@{one.week.ago}
git reflog show HEAD@{yesterday}
git reflog show HEAD@{two.minutes.ago}
git reflog show HEAD@{one.minute.ago}
git reflog show HEAD@{2.days.ago}
git reflog show HEAD@{two.days.ago}

git diff main@{0} main@{yesterday}
git checkout feat:v1.0.5@{2.days.ago}
git reflog mater@{one.week.ago}

Rescuing Lost Commits

  • Find the commit by using git reflog, then git reset to the commit
    • git reflog show HEAD/{branch_name}
git reset --hard master@{1}

Tags:

Categories:

Updated: