最佳解决方法

重要提示:如果您有任何本地更改,将会丢失。无论是否有--hard选项,任何未被推送的本地提交都将丢失。

如果您有任何未被Git跟踪的文件(例如上传的用户内容),这些文件将不会受到影响。

下面是正确的方法:

git fetch --all

然后,你有两个选择:

git reset --hard origin/master

或者如果你在其他分支上:

git reset --hard origin/<branch_name>

说明:

git fetch从远程下载最新的,而不尝试合并或rebase任何东西。

然后git reset将主分支重置为您刚刚获取的内容。 --hard选项更改工作树中的所有文件以匹配origin/master中的文件


[*]:值得注意的是,在重置之前可以通过从master创建一个分支来维护当前的本地提交:

git checkout master
git branch new-branch-to-save-current-commits
git fetch --all
git reset --hard origin/master

在此之后,所有旧的提交都将保存在new-branch-to-save-current-commits中。然而,没有提交的更改(即使staged)将会丢失。确保存储和提交任何你需要的东西。

转载: https://vimsky.com/article/3679.html

how to force git to overwritten local files的更多相关文章

  1. Force git to overwrite local files on pull 使用pull强制覆盖本地文件 转载自:http://snowdream.blog.51cto.com/3027865/1102441

    How do I force an overwrite of local files on a git pull? I think this is the right way: $ git fetch ...

  2. Github Clone to local files

    cd to you local files address key the word: git clone -0 github https://github.com/xxxxxxxxx Done... ...

  3. [Practical Git] Remove unnecessary git tracking with .gitignore files

    Most projects have automatically generated files or folders from the operating system, applications, ...

  4. npm run eject 命令后出现This git repository has untracked files or uncommitted changes错误

    npm run eject 暴露隐藏的文件,不可逆 结果出现下面的问题 This git repository has untracked files or uncommitted changes: ...

  5. git之删除untrack files

    退回版本 git reset --hard commit_id //不保留未提交的修改 git reset --soft commit_id //默认方式,保留未提交的修改 撤除本地没有提交的修改 g ...

  6. git error: Your local changes to the following files would be overwritten by merge:xxxxxx ,Please commit your changes or stash them before you merge.的phpstorm解决办法

    git报错 error: Your local changes to the following files would be overwritten by merge: .idea/encoding ...

  7. git:error: Your local changes to the following files would be overwritten by merge:

    最近用git在服务器.github.本地更新代码的时候,因为频繁修改偶尔出现这个错误 覆盖本地的代码: git stash git pull git stash pop 保留对服务器上的修改: git ...

  8. Git操作删除 untracked files

    最近使用git 管理项目的时候,编译过程中出现了很多中间文件,今天发现使用 git clean 命令可以很方便进行清除: # 删除 untracked files git clean -f # 连 u ...

  9. Git CMD - rm: Remove files from the working tree and from the index

    命令格式 git rm [-f | --force] [-n] [-r] [--cached] [--ignore-unmatch] [--quiet] [--] <file>…​ 命令参 ...

随机推荐

  1. python读取ubuntu系统磁盘挂载情况

    磁盘挂载 利用df -h  的命令 此功能主要实现了python 命令行执行函数进行解析df 返回的数据   代码如下 : # liunx 系统获取 磁盘挂载的情况 代码 #!/usr/bin/pyt ...

  2. CRM WebClient UI的浏览器打印实现

    WebClient UI上自带了一个打印按钮,按Ctrl + P后可以生成一个新的页面供打印. 如下图所示.可以看到这个页面里所有的超链接都已经被移除了. 这个页面的生成逻辑如下. 1. 按住ctrl ...

  3. SpringCloud之Ribbon负载均衡配置

    一.负载均衡解决方案分类及特征 业界主流的负载均衡解决方案有: 1.1 集中式负载均衡 即在客户端和服务端之间使用独立的负载均衡设施(可以是硬件,如F5, 也可以是软件,如nginx), 由该设施负责 ...

  4. 7. Function Decorators and Closures

    A decorator is a callable that takes another function as argument (the decorated function). The deco ...

  5. Kinect视频中运用全身运动和人体测量统计学的人物识别技术

    摘要: 对于人物识别技术来说,动作和人体测量统计学对于光学差异并不敏感,甚至对于眼镜,头发,帽子的描述相当粗糙,现在的以步态为基础的识别技术都是基于对细节的精确描述和对步态周期的精确测量.这种方法需要 ...

  6. Ubuntu系统---安装搜狗输入法

    Ubuntu_搜狗输入法 第一步: 1,下载搜狗输入法的安装包. 下载地址为:http://pinyin.sogou.com/linux/ ,如下图,要选择与自己系统位数一致的安装包,我的系统是64位 ...

  7. 一图一知-TS之symbol

  8. Appium Desired Capabilities-General Capabilities

    Desired Capabilities are keys and values encoded in a JSON object, sent by Appium clients to the ser ...

  9. [NOI2016]循环之美——结论+莫比乌斯反演

    原题链接 好妙的一道神仙题 题目大意 让你求在\(k\)进制下,\(\frac{x}{y}\)(\(x\in [1,n],y\in [1,m]\))中有多少个最简分数是纯循环小数 SOLUTION 首 ...

  10. CF901C Bipartite Segments[点双+二分+前缀优化]

    不想翻译了,直接放luogu翻译 说了没有偶环,也就是说全是奇环,再结合二分图性质,那么暴力的话,固定左端点,增大序号,加点直到产生环就不合法了.也就是说,任何一个环,只要他上面的数全都被加了,就不合 ...