删除.git后,如何进行git pull remote和(重新)初始化本地项目? [英] How to git pull remote and (re)initialize the local project after .git removal?

查看:442
本文介绍了删除.git后,如何进行git pull remote和(重新)初始化本地项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

很难解释,但是基本上我有一个克隆的远程存储库,该存储库已删除了其本地.git信息.一些工作已经完成;但是现在我需要将其重新集成到远程仓库中;如何使用远程git repo初始化"本地项目?我知道我可以git init,但是我不想丢失历史记录或提交内容等.

Hard to explain, but basically I have a cloned remote repository that has had its local .git information removed. Some work has been done; but now I need to integrate it back into the remote repo; how do I 'init' the local project with the remote git repo? I know I can git init but I do not want to lose history, or commits, etc.

推荐答案

假定您最后签出的SHA的SHA为abc123,请执行以下操作:

Assuming that the SHA of the last commit you had checked out was abc123, do the following:

git init .
git checkout -b my_branch (where my_branch is a new branch name you made up)
git remote add origin <url of your remote repository>
git fetch
git reset abc123
git commit -am "Here are my changes"
git checkout master (or whatever branch you were on before you deleted .git)
git merge my_branch

如果您不知道最后一次提交的确切提交,那么如果您选择了之前实际提交的提交,则此方法将起作用;您走得越远,合并冲突就会越多.不要选择在您上一次实际提交之后 发生的提交,因为那样会导致您丢失更改.

If you don't know the exact commit you were last on, this will work if you pick any commit that is before the actual commit you were last on; the further back you go, the more merge conflicts you will have. Don't pick a commit that happened after the the actual commit you were last on, as that will cause you to lose changes.

这篇关于删除.git后,如何进行git pull remote和(重新)初始化本地项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆