You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Git技术问询:如何用单条命令丢弃本地修改/提交并回到上次拉取版本

How to Discard All Local Changes & Commits and Revert to the Last Pulled Version in Git

Hey there! Let's cut straight to the solution you're looking for. If you want to completely wipe out all local changes (staged or unstaged) and any local commits you’ve made, and jump right back to the exact state of the last version you pulled from the remote repository, here’s the single command you can run:

git reset --hard origin/<your-branch-name>

Quick breakdown of what this does:

  • git reset --hard: This tells Git to reset your working directory and staging area to match the specified commit, discarding all uncommitted changes and moving your HEAD pointer directly to that commit.
  • origin/<your-branch-name>: Replace this with your actual working branch (like origin/main or origin/develop). This points to the latest version of the branch stored on the remote server—exactly the state you had after your last pull.

⚠️ A quick warning: This command is destructive. Once you run it, you won’t be able to recover those discarded local changes or commits. Double-check you don’t need anything from your local work before executing it!

内容的提问来源于stack exchange,提问作者Igor K

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.26 09:47:23