Git recovery branch, recover Branch

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.