The reset command has 3 different ways:
- Git reset–mixed: This is the default, git reset without any parameters, in this way, it rolls back to a version, only retains the source code, fallback commit and index information
- Git reset–soft: Fallback to a version that only returns the commit information and does not revert to the index file level. If you want to submit it, you can do it directly.
- Git reset–hard: Completely fallback to a version, the local source code will also become the previous version of the content
Here are some examples of reset:
(1) Fallback all content to previous version
git reset head^
(2) Fallback a.py version of this file to the previous version
git reset head^ a.py
(3) Forward fallback to 3rd version
Git reset–soft head~3
(4) Fallback the local state to the same as the remote
Git Reset–hard origin/master
(5) fallback to a version
git reset 057d
(7) Fallback to the state of the last commit, followed by a commit that was completely reversed in one commit
git revert HEAD
If we have changed something and have already made a commit to the local repository, and have already been push to the remote repository
In this case, we want to back up the local and remote repositories to a version, what to do?
The previous git reset is just a fallback version in the local repository, and the version of the remote repository does not change
This way, the local reset is immediate, but if you do git pull again, the contents of the remote repository will merge with the contents of the previous version of the Local
This is not what we want, there are 2 ways to solve this problem:
- Run git reset–soft 10efa back and forth directly in the remote server's warehouse directory. Note: Mixed or hard parameters cannot be used at remote
- The remote Master branch is deleted locally, and then the branch content after reset is sent to push, as follows:
(1) New Old_master branch for backup
git branch old_master
(2) push to remote
git Push Origin old_master:old_master
(3) Local warehouse fallback to a version
git Reset–hard bae168
(4) Delete the remote Master branch
git Push origin:master
(5) Re-create Master branch
git push Origin master
There may be a problem when deleting the remote Master branch, see below:
$ git push origin:master
Error:by default, deleting the current branch is denied, because the next
Error: ' Git clone ' won ' t result in any file checked out, causing confusion.
Error
Error:you can set ' receive.denydeletecurrent ' configuration variable to
Error: ' Warn ' or ' ignore ' in the remote repository to allow deleting the
Error:current Branch, with or without a warning message.
Error
T ">error:to squelch this message, you can set it to ' refuse '.
Error:refusing to delete the current Branch:refs/heads/master
to [email protected]:gitosis_test
! [Remote rejected] Master (deletion of the current branch prohibited)
Error:failed to push some refs to ' [email protected]:gitosis_test '
In this case, you need to set Git's receive.denydeletecurrent parameter in the remote repository directory.
Git receive.denydeletecurrent warn
Then, you can delete the remote Master branch.
Although there are 2 ways to go back to the remote branch version, but these 2 ways, are quite dangerous, need to be cautious operation ...
Git version restore command reset