Skip to content

Revert

一句话解释

Reverting 创建新 提交那个 undoes 更改的 specified 提交, preserving 原始 history.

用大白话说

git revert <commit> creates a new commit that is the exact inverse of the specified commit. If the original commit added a line, the revert removes it. If the original changed a value, the revert changes it back.

Revert is the safe way to undo a commit on shared branches because it adds to history rather than rewriting it. The original commit stays in the log — anyone who has already pulled is not affected.

This is different from git reset, which moves the branch pointer and effectively "删除" commits from history (rewriting it). Use revert for shared branches (main, develop) and reset for local branches where rewriting history is acceptable.

示例

bash
# Revert the last commit
git revert HEAD

# Revert a specific commit
git revert abc123

# Revert without opening editor
git revert --no-edit abc123

Revert 创建新 提交那个 undoes specified 提交's 更改.

常见混淆

  • 容易混淆的对象: reset

    关键区别: revert 添加新 提交那个 undoes 更改 (safe, preserves history); reset moves 分支指针向后 (rewrites history, dangerous for shared 分支).

相关术语

相关资源

相关课程

解读错误信息

用大白话解释常见错误——什么意思、为什么发生、如何修复。

查看错误

← 返回术语表