Some mistakes may occur during git usage.
For example, execute checkout-F, reset-hard, or branch-D to delete a branch.
As a result, the local (remote) branch or some commit is lost.
At this time, we can use reflog to restore the service, provided that the lost branch or commit information is not cleared by git GC.
In general, GC will be retained for those useless objects for a long time before being cleared.
Reflog is an internal tool provided by git to record various operations performed on the GIT repository.
You can use git reflog show or git log-G command to view all operation logs.
The recovery process is simple:
1. Use the GIT log-G command to find the commitid corresponding to the information we need to recover. You can identify it by the submission time and date.
2. Use git branch recover_branch commitid to create a new branch
In this way, we can restore the lost items to the recover_branch branch.