Home > Article > Development Tools > How to restore all changes in git
Method: 1. When the file has no git operation, use the "git checkout --file" command to restore it; 2. When the file is submitted to the temporary storage area, use the "git reset HEAD" command to roll back to the current version and restore it; 3. When submitting files to the warehouse area, use the "git reset HEAD^" command to roll back to the previous version.
The operating environment of this article: Windows 10 system, Git version 2.30.0, Dell G3 computer.
How to restore all modifications in git
There are three situations for restoration:
Only modified files , without any git operation
The file was modified and submitted to the temporary storage area (that is: after editing, git add was performed but there was no git commit -m "Message xxx")
The file was modified and submitted to the warehouse area (i.e. after editing, perform git add and git commit -m "leave a message xxx")
If If it is case 1:
git checkout -- aaa.html // 指定还原`aaa.html`文件 git checkout -- * // 还原所有文件
If it is case 2:
git log --oneline // 可以省略 git reset HEAD // 回退到当前版本 git checkout -- aaa.html
If it is case 3:
git log --oneline // 可以省略 git reset HEAD^ // 回退到上一个版本,注意看HEAD后面有个 ^HEAD^ 是回退到上个版本HEAD^^ 是回退到上上个版本HEAD~数字 是回退到数字个版本 git checkout -- aaa.html
Recommended learning: "Git Tutorial"
The above is the detailed content of How to restore all changes in git. For more information, please follow other related articles on the PHP Chinese website!