git - 本地目录和远程存储库之间的连接丢失
问题描述
我有一个本地目录,是大约一年前通过克隆远程存储库创建的。从那时起,我对本地代码进行了数百次更改,但目录中不再存在 git 文件,这意味着与远程存储库的连接已丢失。同时,自从我第一次克隆远程存储库以来,它已经进行了数百次更改。
现在,我想重新建立该连接,并将远程存储库中的任何新更新拉到我的本地目录中。
我该怎么做呢?
解决方案
According to your comments you have lost your .git repository and your directory has a lot of updates from the last time you synced with the remote.
If you lost your .git repository then you cannot restore any commit which happened between the last push from you lost repository till it got lost.
What you can do, is to create another local repository from the remote one and manually merge your files into it.
git clone your-remote-repo your-local-repo
git checkout -b your-restore-branch
, just make a different branch for restoring- copy your files itno your-local-repo
git diff --name-status
will show the differences between the tip of the branch and the files which you copied- manually review all the differences and decide what you want to do with them
- when you done your merge work, commit all the changes in the your-restore-branch by
git commit
; You might want to do several commits. do testing. - check out the original branch
git checkout master
(or whatever branch name you had) git merge your-restore-branch --squash
merge into the main branch, ignoring your manual merge history. then do your testing again andgit commit
for the results of the merge.- when you done, you can do
git push
into the remote repo.
推荐阅读
- mysql - 比较两个结果集
- python - ValueError:检查输入时出错:预期 input_1 有 4 个维度,但得到了形状为 (6243、256、256) 的数组
- java - 如何在 Hadoop 中获得最大字数?
- android - Google Playstore 发布 - 为 OTP 自动读取选择哪个用例?
- google-apps-script - Google Apps 脚本从 getPlainBody() 中找到 URL?
- sql - BigQuery SQL 查询优化
- node.js - Nunjucks:如何使用自定义扩展绕过自动转义?
- python - rpyc服务器调用客户端方法
- reactjs - 在 React 中显示初始加载的加载屏幕
- python - pandas - 如何将聚合数据转换为字典