LN_02 Git放弃本地更改,强制从远程仓库Pull最新代码
问题描述:我修改了本地代码,但想用gitee仓库中的旧版本覆盖本地代码,在直接尝试git pull origin从远程仓库拉取最新版本到本地时出现问题,
# 报错信息如下
$ git pull origin master
remote: Enumerating objects: 18, done.
remote: Counting objects: 100% (18/18), done.
remote: Compressing objects: 100% (9/9), done.
remote: Total 10 (delta 5), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (10/10), 2.57 KiB | 64.00 KiB/s, done.
From https://gitee.com/preyers/picture-list-component
* branch master -> FETCH_HEAD
564703d..ce58456 master -> origin/master
error: Your local changes to the following files would be overwritten by merge:
components.d.ts
package-lock.json
package.json
src/App.vue
Please commit your changes or stash them before you merge.
Aborting
Updating 564703d..ce58456
解决方案原文:https://blog.csdn.net/weixin_38959210/article/details/136379502
git fetch --all
git reset --hard origin/master
git fetch --all将从远程仓库中抓取(fetch)最新更改到本地,但不会自动合并。--all选项确保将远程仓库(origin、upstream等)的所有配置抓取到本地进行更新。
git reset --hard origin/master会将当前分支重置为origin/master状态。--hard选项意味着所有工作目录中的更改和暂存区的更改都将被丢弃,本地仓库将完全匹配origin/master的状态。这是一个破坏性的操作,会丢所有未提交的更改