Git reset
1. File rollback from staging area to workspace 2. Version rollback
1.1 git reset HEAD filename : roll back the file, roll back the file from the staging area to the workspace // you can also use git reset filename
1.2 git reset HEAD^ : rollback version, one ^ means one version, there can be multiple versions, and the form of git reset HEAD~n can also be used.
If the HEAD pointer points to the master branch, then HEAD can also be changed to master. If you know the specific commit-id, you can also use git reset commit-id directly. If no parameters are added, the default parameter mixed is actually used.
We can use git log -3 to view the last three commits, in the form of git log -n, where n is the number of outputs you want, you can see commit-id, author, date and other information
The three parameters are described below:
(1) soft parameter : git reset --soft HEAD~1 means to roll back one version of the repository softly, the so-called soft rollback means to reset all the head pointers of the local repository to the specified version, and commit this time All subsequent changes are moved to the staging area
(2) The default mixed parameter : git reset HEAD~1 means to roll back the repository by 1 version, reset all the head pointers of the local repository to the specified version, and reset the staging area, that is, this commit All subsequent changes are moved to the unstaged stage
(3) Hard parameter : git reset --hard HEAD~1 means to roll back the repository by 1 version, but not only resets all the head pointers of the local repository to the specified version, but also resets the staging area , and will rollback the workspace code to this version as well
Knowing these three parameters is enough for our daily development and use. Note that neither the soft parameters nor the default parameters will modify the workspace code, and only the hard parameters will modify the workspace code.
1.3 git reset cooperates with git commit to add commits
When is append commit used and what are the advantages of append commit?
(1) If you are not satisfied with the commits in the unmerged repository and want to modify some of the information, such as the code, such as the commit description, etc., you can use git commit --amend to make additional commits. The advantage is that no new commits will be generated. -id
(2) Modification method: If what you want to modify is not the latest version of the submission, you can roll back the version to the required version through git reset --hard HEAD~n. If you want to modify the code, then directly code in the workspace Revise,
After the modification, git add to the staging area without git pull, and if you want to modify other information, you can directly use git commit --amend to make additional submissions. The git commit --amend command will open an editor, which can be modified Information,
If the code is modified without modifying other information, just Ctrl + X to leave the editor, and then git push push to the remote server. If other information is also modified, you need to use Ctrl + M to write the information first, and then Ctrl + X to leave editor, and then push.
1.4 View help
git reset -h | git reset --help