Git提供了多种方式来撤销更改,取决于具体情况——舍弃未提交的更改、取消暂存、修正上次提交、还原提交或重置。了解针对每种情况的正确工具是重要的、频繁需要的实用技能。
撤销未提交的更改(工作目录)
git restore <file> # discard unstaged changes to a file (revert to last commit)
git checkout -- <file> # older equivalent
git restore . # discard ALL unstaged changes (careful!)
git clean -fd # remove untracked files/directories
取消暂存(保留更改,只取消暂存)
git restore --staged <file>
git reset <file>
