Home > Development Tools > git > How to restore all changes in git

How to restore all changes in git

WBOY
Release: 2022-01-07 15:14:39
Original
33437 people have browsed it

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.

How to restore all changes in git

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 -- * // 还原所有文件
Copy after login

If it is case 2:

git log --oneline            // 可以省略
git reset HEAD               // 回退到当前版本
git checkout -- aaa.html
Copy after login

If it is case 3:

git log --oneline    // 可以省略
git reset HEAD^     // 回退到上一个版本,注意看HEAD后面有个 ^HEAD^ 是回退到上个版本HEAD^^ 是回退到上上个版本HEAD~数字 是回退到数字个版本
git checkout -- aaa.html
Copy after login

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!

Related labels:
git
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template