1. Method 1: git reset
Directly roll back to the specified version, and commits after the target version will be deleted.
Situation 1: " git reset --hard repository address ", the pull server specifies submission to the staging area, this operation does not affect the workspace.
Step 1: Execute "git reset --hard repository address" to pull the server specified version to the local staging area.
Check the log and you can see that the version has been rolled back to the target version.
Step 2: "git checkout file name", pull from the staging area to the workspace.
Scenario 2: "git reset --hard HEAD^" : Pull the latest submission from the server to the staging area. This operation does not affect the workspace.
Then execute "git checkout file name" to pull from the staging area to the workspace.
"Note: If the push operation is not performed, you can directly execute "git checkout file name" and pull the staging area to replace the workspace."
2. Method 2: git commit --amend
If the content of the last submission is incorrect and you want to make changes, but do not want to make a new submission , use git commit – amend.
Steps:
1. Correct the content and execute "git add";
2. Execute "git commit --amend";
3. Automatically enter vim and prompt that you need to add commit information. Input: "i" to add information "delete fff", "esc", "wq" to exit and save;
4. Execute "git push -f" to successfully push to the server (git push will prompt an error: the current staging area version is lower than The server version is committed once).
Note: amend submission information will be appended to the latest submission information.