美文网首页
github不小心同步覆盖了本地文件

github不小心同步覆盖了本地文件

作者: qwerer | 来源:发表于2017-08-08 10:49 被阅读0次

我在两个电脑上修改一个项目,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

然后

git reset --hard 502dd0f
git cherry-pick 147b3b5

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

git push origin master

但出现:

! [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.

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

git pull
如果有冲突,解决冲突
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>

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

git checkout -b temp
git checkout master

相关文章

  • github不小心同步覆盖了本地文件

    我在两个电脑上修改一个项目,A修改文件a,B修改文件b。然后我干了下面这些事,按时间顺序。。。 A上 git co...

  • github本地部署同步远程文件

    1.github里面建立仓库 1、首先在github里面新建一个仓库 2、创建test仓库 3、创建成功后如图显示...

  • 红尘来去两袖空,天地乾坤在我胸 --git命令总结

    在github上创建第一个工程,添加一个README.md 在本地新建一个文件夹,同步远程代码 在本地添加文件da...

  • GitHub同步本地项目

    这篇不想写了,直接看http://www.cnblogs.com/Chenshuai7/p/5486278.htm...

  • 下载、同步项目

    下载项目 在本地找到你想放文件的路径,右键打开GitHub窗口, git clone 项目链接 同步项目 方法一查...

  • Git&Github基本操作

    Github三大分区 同步Github仓库Repository到本地:1.在Github官网新建一个仓库2.本地G...

  • 将本地项目上传至 Github

    本地新建项目后,如何同步到 github 上呢? 在GitHub上新建项目 进入本地项目目录,依次执行git in...

  • uBuntu Rsync文件同步服务

    安装Rsync文件同步服务 uBuntu系统默认安装Rsync服务,查看帮助文档: 本地文件夹同步命令: 同步到远...

  • [Win] 同步备份工具Goodsync v10.9.32.2

    Goodsync 可以说是目前最好用的的文件同步工具,可以支持双击同步,单向备份,多任务的同步工具.本地文件同步、...

  • rsync

    一、作用:文件同步和快速传输工具,可实现文件快速备份(本地备份或将本地数据备份到远程服务器),rsync首次是同步...

网友评论

      本文标题:github不小心同步覆盖了本地文件

      本文链接:https://www.haomeiwen.com/subject/mbqtrxtx.html