Skip to content

Force 推送

一句话解释

Force pushing overwrites remote 分支使用你的局部 history, potentially destroying 提交那个 others 有 pushed.

用大白话说

git push --force (or -f) overwrites the remote branch with your local version, discarding any commits on the remote that you do not have locally. It is the nuclear option of pushing.

Force push is needed after rewriting history with rebase or amend — the remote must be overwritten to match your new history. But if someone else has pushed commits you do not have, those commits are destroyed on the remote.

The safer alternative is git 推送 --force-使用-lease, which only force-pushes if the remote is at the same commit you last fetched. If someone else has pushed, the force push is rejected, preventing you from destroying their work. Always prefer --force-with-lease over --force.

示例

bash
# Dangerous: may destroy others' commits
git push --force origin feature

# Safer: only force-push if no one else has pushed
git push --force-with-lease origin feature

Force 推送 overwrites remote history. --force-使用-lease 是 safe version.

相关术语

相关资源

相关课程

解读错误信息

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

查看错误

← 返回术语表