Загрузка видео...

Не удалось загрузить видео

На главную

Test your git knowledge with this developer challenge: after a git reset, three commits are removed from the log, but now you realize you need them back. What are your options? Share your answer in the comments.

13,519 просмотров • 6 месяцев назад •via X (Twitter)

Комментарии: 9

Фото профиля Google for Developers
Google for Developers6 месяцев назад

A hard reset moves the branch, but old commit references can still be recorded for a while. Which Git tool remembers where HEAD used to point?

Фото профиля Google for Developers
Google for Developers6 месяцев назад

Result: Yes, those commits usually are recoverable for a while. Why: git reset --hard HEAD~3 moves the branch pointer back three commits and resets the working tree, but it does not immediately delete the old commits. They usually remain reachable through the reflog until Git garbage collection removes them. How to get them back: Use git reflog to find the old commit or previous HEAD, then reset back to it or create a new branch from it.

Фото профиля Rutesh Rathod
Rutesh Rathod6 месяцев назад

Yeah, those commits aren’t actually gone. git reset --hard HEAD~3 just moves the pointer back, it doesn’t delete them. You can still recover them using git reflog, find the commit before the reset, and reset back to it.

Фото профиля Google for Developers
Google for Developers6 месяцев назад

Thanks for looking out for the community’s commits. 🤝

Фото профиля faych
faych6 месяцев назад

yes, those three commits still exist, we can use git reflog to get the first commit hash and git reset to it with --hard.

Фото профиля Moksy AI
Moksy AI6 месяцев назад

@googledevs Recover via reflog magic

Фото профиля Ryan White
Ryan White6 месяцев назад

I'd check reflog. Like a save scum for your repo. Don't tell juniors how close they came.

Фото профиля Mervlot | Software & Web Development
Mervlot | Software & Web Development6 месяцев назад

Yeah I don't use git that deep but please it will be nice to see someone show me how to do this anything could happen 🥺

Фото профиля Hybrid 🏃🏾
Hybrid 🏃🏾6 месяцев назад

reflog

Похожие видео