git use manual/git Tutorial: Retrieve deleted version code/git Reflog and git log difference/Cancel registers file's staging __ Retrieve the deleted version code

Source: Internet
Author: User
Tags diff ssh git clone
Related articles:For a way to verify that an SSH configuration exists and generate an SSH key, refer to the article: Git usage manual: Generate SSH key for SSH key usage and public key in GitHub, Gitlab configuration, please refer to article: Git usage manual: Use SSH key and configure SSH Key public key on the concepts and relationships of Git workspaces, registers, local warehouses, and remote warehouses, please refer to the article: Git manuals: workspaces, registers, local warehouses, remote warehouses about git downloading items from a remote repository to a local workspace, see article: Git manual: Git Clone Clone download Remote warehouse Project project to local workspace For more information about GIT branch use, please refer to article: Git Manual: Git branch Branch operations, create a branch, view a branch, delete a branch, delete a local branch, delete a remote branch

For the use of Git checkout, please refer to the article: Git manual: Git checkout Create branches, toggle branches

For an explanation of the git status command, please refer to the article: Git manual: Git status View changes to files in the local workspace, registers

For the use of Git diff and git add commands, please refer to the article: Git Usage manual: Git diff, git Add, git diff--cached command details

For a detailed explanation of git commit commands, please refer to the article: Git manual: Git commit-m/-am/-a-m submit files to local warehouse area

For a git fetch command, refer to the article: Git manual: Git fetch pulls the latest version of the branch and branch of the remote warehouse to the local

For more information about git pull command use, please refer to article: Git manual: Git pull origin pull substitution code to local, resolve file conflicts when pulling out code

For a git push command use, please refer to article: Git manual: Git push forward submit local warehouse code file to remote warehouse
For more information about git log commands, please refer to the article: Git manual/git Tutorial: Git log view git submit version history logging

For the git reflog command use, please refer to the article: Git manual/git Tutorial: Git reflog Use, view historical version record about git reset command use/git version fallback, please refer to article: Git manual/git tutorial: git reset Use/ Git reset mixed soft hard use detailed and different/git code version fallback



1 Retrieve the deleted version code and create a new branch

In combination with the previous article git use manual/git tutorial: Git reset using/git reset mixed soft hard Use the detailed and different/git code version fallback, after the last git reset--hard operation, will not retain the specified version of the Code, Also, git log cannot see the submitted version history after the specified version, and if we want to retrieve the lost version of the code, we can use the following command:

Command: Git checkout-b branch name commit ID

Role: Creates a new branch based on the version content of the specified commit ID, so that the contents of the new branch are the contents of the specified version.

In conjunction with the previous article, we first use Git reflog to view the submitted version history:


Above, the result of Git reflog after we use git reset--hard, where the version 7cd6092 version of the code no longer exists.

If we want to retrieve the 7cd6092 version of the code, we can use the previous mentioned command, the results of the implementation of the figure:


As shown in the figure, we have created a branch named Backup-code, and after switching to the specified branch, we can see the code content of the version 7cd6092.

or use the following command:

Command: Git branch branch name Commitid

This command also achieves the effect of the GIT checkout-b branch name commitid command, creating a new branch based on the contents of the specified Commitid version.

As for the difference between the two, please refer to my previous article: Git Manual: Git branch Branch operations, create branches, view branches, delete branches, delete local branch, delete remote branch and git manual: Git checkout Create branches, toggle branches

2 The difference between git reflog and git log look at my previous article git use manual/git tutorial: Git reset using/git reset mixed soft hard use details and distinguish/git code version back to the small partners should be aware, In the previous article, you used git log and git reflog more than once to view the submitted version history, but did not explain the two, and here's an explanation: borrow the picture from the previous article: when we use git reset command to go back backward (no option is considered here, Because the description is git reflog and git log, and git reset option does not affect the results, I used git log and git reflog to view the submitted version history, as shown in the following illustration: git log execution results:
git Reflog Execution Results:
Note: The picture here is excerpted from the previous article: git use manual/git tutorial: Git reset to use/git reset mixed soft hard use the details and differences/git code version back to perform git reset--mixed head~2 command section, You can copy the Red Font command to the article to find the specific content.
As we can see from the previous illustration, 5 records are also displayed, and the commit ID of the first record in git log is c3b8692, the same as the commit ID of the first record in Git reflog; the commit ID of the second record in git log is 33cbf73, and Git Reflog is c769c03, from here found that two commands show different results.
The reason for this is that git log looks at the submission version history and does not contain the missing commit history due to a rollback command such as git reset. Git Reflog is looking at all of the project's submitted version history, including the submission history of various operations commands (such as checkout, commit, reset, pull, and so on), more specific, equivalent to the operational log.
So the use of the scenario is different, the reason for the last article to use both is to show the general effective version of the record view, combined with all the submitted version of Git Reflog history, together in the reset operation more intuitive to see the changes.
When a fallback is required, it is also recommended that the small partner be used together with 2 commands.

3) Cancel registers file's temporary storage
When we edit a number of files in the current workspace, when you save the registers, and you find that there are incomplete functionality code or write the wrong content, you cannot submit files that involve these issues to the local warehouse, you can withdraw the specified file from the registers, which will not affect the submission of other files. facilitate subsequent use. Command: git reset head filename where filename can be an absolute path, or a relative path. First we modify the file to view the file status:
As we can see in the picture, the file has been modified and not stored in registers. We then proceed to the registers operation and look at the status of the current workspace, as shown in figure:
You can see that when you save the registers, you are prompted to view the status and the changes can be submitted. Documents that have been modified are deposited in the registers. If we find a problem with the contents of the file and cannot submit it, we need to execute the above mentioned command: Git reset head fileName, as shown in the following illustration:
After execution, you can see that a line of prompts appears: Unstaged changes after reset, indicating that the changes have not been staged. We look at the local workspace again, as shown in the figure:
Found that the file is already back in the workspace and is in the pending state.





If you have other questions, I hope that through the form of a message to communicate in a timely manner, there are written errors and can be optimized places also hope to make timely, thank you.

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.