昨天不小心github的commit还没push就同步了,导致本地文件被覆盖,一度以为没救了。 后来得微博 @空非无和 @柳烟堆雪 指点,用git reflog 恢复了文件。

事情是这样的。。。 
我在两个电脑上修改一个项目,A修改文件a,B修改文件b。然后我干了下面这些事,按时间顺序。。。 
1. A上 git commit 
2. A上 git push 
3. B上 git commit 
4. B上 git pull 
然后。。。B上修改的b就被覆盖了。。。

而且git log已经找不到第3步的commit了。


解决方案: 
执行git reflog

502dd0f HEAD@{0}: pull --progress --rebase --prune origin master
147b3b5 HEAD@{1}: commit: commit-mark
502dd0f HEAD@{2}: rebase finished: returning to refs/heads/master
  • 1
  • 2
  • 3

然后

git reset --hard 502dd0f
git cherry-pick 147b3b5
  • 1
  • 2

就可恢复原来B上的本地文件, 然后push到服务器端:

git push origin master
  • 1

但出现:

 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/GitUsername/GitProgramName.git'
hint: Updates were rejected because a pushed branch tip is behind its remote
hint: counterpart. Check out this branch and integrate the remote changes
hint: (e.g. 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

可见,线下线上文件出现了冲突。 
解决方法:

  1. git pull
  2. 如果有冲突,解决冲突
  3. git push

但是git pull出现问题:

You are not currently on a branch. Please specify which
branch you want to merge with. See git-pull(1) for details. git pull <remote> <branch>
  • 1
  • 2
  • 3
  • 4

解决方法:切换到master,再执行git push

git checkout -b temp
git checkout master from: http://blog.csdn.net/abcjennifer/article/details/45101153

github不小心同步覆盖了本地文件的更多相关文章

  1. github创建项目,并提交本地文件

    1.如图所示,不要点选"Initialize this repository with README",不然就看不到第二幅图的提示信息了 2.根据下面提示,初始化本地文件,然后上传

  2. 如何与GitHub同步,将本地文件push到到远程仓库

    Run git config --global user.email "you@example.com" git config --global user.name "Y ...

  3. 恢复不小心误覆盖的代码文件 (sublime编辑器)

    最新写了一个python脚本,另外在终端上运行一个shell脚本循环记录一些性能.耗时参数.取出记录的数据,使用python pyplot强大的绘图功能来可视化,易用程度仅次于matlab. 本次文件 ...

  4. git——同步本地文件到github上

    参考教程: 1.https://blog.csdn.net/weixin_37769855/article/details/99439904 2.https://www.liaoxuefeng.com ...

  5. 将本地文件夹同步到github仓库中

    参考博客 本地生成rsa密钥 cd ~/.ssh # 查看是否已经生成过密钥 ssh-keygen -t rsa -C "username on github" # -C表示注释 ...

  6. github 创建网络仓库 ,使用git工具将本地文件上传/删除 --- 心得

    1.前言 使用  git做项目控制版本工具,当然,使用SVN也可以,但是,git让人感觉更先进一些,与GitHub结合,用起来很方便,服务端由官网控制. 而SVN分客户端和服务端,都是个人控制,因此, ...

  7. Git安装及密钥的生成并上传本地文件到GitHub上

    之前用的GitHub,不太熟练,一直在上传的过程中遇到了一些问题,看了网上诸多教程,总觉得很乱,特参考一些资料,总结了一篇完整的操作步骤,从下载安装到上传文件,亲测有效 1.下载Git软件:https ...

  8. 自动将本地文件保存到GitHub

    前言 只有光头才能变强. 文本已收录至我的GitHub精选文章,欢迎Star:https://github.com/ZhongFuCheng3y/3y 这篇文章主要讲讲如何自动将本地文件保存到GitH ...

  9. 本地Git仓库与GitHub/GitLab仓库同步

    本地仓库即为在你的电脑上的项目文件,远程仓库即为服务器仓库,如GitHub.GitLab或其他等.此处以GitHub介绍本地仓库与远程仓库的同步.可先创建本地仓库,也可先创建GitHub仓库,但都需要 ...

随机推荐

  1. C# 或 JQuery导出Excel

    首先要添加NPOI.dll文件 然后添加类:NPOIHelper.cs using System; using System.Data; using System.Configuration; usi ...

  2. hibernate tool连接oracle生成pojo和xml文件无法查询表解决办法

    需要在hibernate的配置文件中增加 <property name="hibernate.default_schema">[username]</proper ...

  3. How to Build FFmpeg for Android

    http://www.roman10.net/how-to-build-ffmpeg-for-android/ ffmpeg is an open-source platform for record ...

  4. 安装Symfony2

    我就不明白这个框架明明很小就几M,为什么这么难下载. 他们为什么不把文件打包好?非要搞得这么复杂. 一开始我在Linux ubuntu下载没有成功 然后想在win10上试试 到www.apache.o ...

  5. websphere OSGi应用环境下服务调用saaj包加载问题分析报告

    websphere OSGi应用环境下服务调用saaj包加载问题分析报告 作者:bingjava 版权声明:本文为博主原创文章,转载请说明出处:http://www.cnblogs.com/bingj ...

  6. 【CentOS】设置静态IP

      问题描述:         CentOS配置静态IP   问题解决:         (1)修改IP--修改配置文件/etc/sysconfig/network-scripts/ifcfg-eth ...

  7. ios 百度地图

    百度地图  中的注意事项 1. 百度地图中 使用了c++   设置buidSeting compoileSource 为 Object-C++  强制使用oc++编译器 2. 设置  BuidSeti ...

  8. YEBIS

    在往项目里加yebis做各种后处理 就是看起来很高大上的各种味精 我又热!泪!盈!眶!了 压缩包解开 有各种文档 恩哼~ 大概看了下找到sample build.... 直接就success了.... ...

  9. HDU1058Humble Numbers

     Humble Numbers Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u     ...

  10. django转义safe

    “何谓转义?就是把html语言的关键字过滤掉.例如,<div>就是html的关键字,如果要在html页面上呈现<div>,其源代码就必须是<div> 默认情况下,d ...