最佳解决方法

重要提示:如果您有任何本地更改,将会丢失。无论是否有--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. javaIO——PushbackReader

    1. 注释解释: A character-stream reader that allows characters to be pushed back into the stream. 一个允许字符被 ...

  2. navigateTo防止多次跳转

    “wx.navigateTo” 页面跳转.在有网络延迟时多次点击会产生 多次二级页面 再使用wx.navigateBack就会多次返回到之前那页面 解决办法: 点击之前标个状态true 点击之后跳转路 ...

  3. 构建之法第二次作业【使用git和Vs实现四则运算】

    [相关信息] Q A GIT地址 git地址 GIT用户名 Lin-000 学号后五位 62501 博客地址 博客地址 作业链接 此次作业链接 1.项目需求 程序接收一个命令行参数 n,然后随机产生 ...

  4. CSS 中用户自定义字体 @font-face

    @font-face 允许网页中使用自定义的字体,这些自定义的字体被放置在服务器上,从而让网页摆脱对访问者计算机上字体环境的依赖. 简单的说,有了@font-face,只需将字体上传到服务器端,无论访 ...

  5. es中的相关知识一(基本知识和id的定义)

    一.es中文档的元数据包括: 1._index: 索引(index)类似于关系型数据库里的数据库(database),事实上,我们的数据被存储和索引在分片(shards)中,索引知识把一个或多个分片分 ...

  6. C# 之 .net core -- 创建项目

    一.新建一个Web 的 应用程序 二.选择项目的基本信息(.net coer 2.2 和带有试图控制器的程序) 这个是类似以MVC的模式,也可以用其他的,总之需要什么选什么 三. 然后既可以看到这样一 ...

  7. Hosts 文件切换工具

    建议删除无用的注释,否则在启用全部的时候会把注释和说明内容的注释取消掉 下载地址:

  8. HTML中dl元素的高度问题

    dl元素通常用来创建一个描述列表,但是在我使用的过程中发现了一个小问题. 定义及用法 在MDN中 <dl> 元素的定义是:一个包含术语定义以及描述的列表,通常用于展示词汇表或者元数据 (键 ...

  9. flutter 项目中打印原生安卓的log信息

    因为项目的需要 在flutter 中调用安卓的方法 再用安卓的方法去调用c写的so包 方法 如果当前项目下面没有android stduio 自带的logcat  那就利用下面的方法 在安卓代码中引入 ...

  10. BZOJ 4260: Codechef REBXOR (trie树维护异或最大值)

    题意 分析 将区间异或和转化为前缀异或和.那么[L,R][L,R][L,R]的异或和就等于presum[R] xor presum[L−1]presum[R]\ xor \ presum[L-1]pr ...