git downloads the specified version code

================================================== =======================
Preface:
To download the code of the previous version of the git remote warehouse, I need to roll back the version of a certain project here, so Instead of rolling back the version in the original local library, select another folder, and then the overall operation is:
1) git clone downloads the latest version code;
2) git reset rolls back to the specified version;
command:

git clone [git-url] -b [branch-name] //-b is followed by the name of the specified branch
git reset --hard [commit-number]


1. Download the latest version code of the remote warehouse to the local area;

1-1. In the folder where you want to store the git download code, right-click and select open git bash
(if there is no such option on the right-click, it is because the right-click option was not checked during installation. It can be found in the Windows start menu, as shown in the figure below) (Example:)
Insert image description here
Insert image description here
1-2. Open the remote library (such as github, gitee, etc.) and copy the remote library address, and then use the git clone command to clone the latest code from the remote library to the specified folder: Command
:

git clone <远程库的url>   //克隆远程库到本地

Insert image description here
After he finishes downloading, the local folder will clone a copy of the latest version of the code in the remote warehouse, and the next step is to roll back to the specified version;

2. Roll back to the specified version

2-1. Use the git log command to view historical commit versions
. Command:

git log

Insert image description here
2-2. git reset rolls back to the specified version:
command:

git reset --hard <哈希值> //哈希值即为上面复制的commit后面的那串字符

Insert image description here
At this point, the code of this local library has been rolled back to the version you want to specify;

Guess you like

Origin blog.csdn.net/weixin_42640280/article/details/129969007