Skip to content

Dirty 索引期间 Rebase

错误信息

                错误: cannot rebase: 你有 unstaged 更改.
              

快速摘要

Git refuses 到开始 rebase 因为你有 uncommitted 更改那个会是 lost.

为什么发生

  • 你有修改 files 那个是不 committed or stashed

  • 你有 staged 更改那个是不 committed

  • 你 tried 到 rebase 使用 dirty 工作树

最小示例

✗ 错误代码
git rebase main  # error: cannot rebase: You have unstaged changes.
✓ 修复代码
git stash
git rebase main
git stash pop

Stash 你的 uncommitted 更改, 执行 rebase, 然后 pop stash 到 restore 它们.

如何诊断

  • 运行 git 状态到 see uncommitted 更改

  • Decide 如果更改应该是 committed, stashed, or discarded

如何修复

  • Stash 更改: git stash, 然后 rebase, 然后 git stash pop

  • 提交更改: git 添加 . && git 提交 -m "Save before rebase"

  • Discard 更改: git reset --困难 (destructive — 仅如果你做不需要它们)

如何预防

  • 提交 or stash 之前 rebasing

  • 运行 git 状态之前开始 rebase

相关资源

相关术语

相关课程

← 返回语言