删除了 2 个月的 Git 工作。如何让他们回来?
我真的不知道我刚刚做了什么,所以我只是给出一个时间表。
我今天第一次尝试建立 gitHub 存储库。我有一个文件夹,其中保存了我网站上的所有文件,并且它有一个 .git 文件夹。我经常进行更改等,一切似乎都很好。
今天我尝试合并我正在从事的项目的两个分支。我尝试了“merge”和“rebase”命令,但我无法真正理解发生了什么或我在做什么,所以我决定从 git 开始。
我将 .git 文件夹从我的网站文件夹中取出(我没有删除它,我想这可能是我的可取之处)。在文件夹中执行了一个新的 git Init 并将网站文件提交给它。
就在那时我注意到大量文件丢失了。我认为它们仍在第一个 .git 文件夹中。有没有办法从此文件夹恢复目录?
I don't really know what I've just done so I'm just going to give a kind of timeline.
I was trying to set up a gitHub repository today for the first time. I have a folder where I keep all the files from my site and it had a .git folder. Every so often I was committing changes etc and everything seemed ok.
Today I tried to merge two branches of the project I was working on. I tried "merge" and "rebase" commands but I couldn't really understand what was happening or what I was doing so I decided I'd just start over with git.
I pulled the .git folder out of my website folder (I didn't delete it which I guess could be my saving grace here). Did a new git Init in the folder and committed the website files to it.
That's when I noticed loads of files were missing. I think they're still in the first .git folder. Is there a way I can restore a directory from this folder?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我很惊讶你已经使用 git 工作了两个月,并认为重新开始是从失败的 rebase 中恢复的最佳方式,它应该容易得多。
您应该能够将旧提交恢复到新存储库中,而不会出现太多问题。
您可以添加一个新的遥控器,它是您旧保存的存储库:
然后您可以获取所有旧历史记录。
然后你可以打开历史浏览器(例如
gitk --all
)来查看旧的历史记录。您可以使用以下命令检查丢失文件的版本:
old/master
指的是旧存储库中的 master 分支,不过您可以在此处使用任何分支或提交的 ID。I'm surprised that you've been working for two months with git and decided that starting over was that best way to recover from a failed rebase, it should be a lot easier.
You should be able to recover your old commits into the new repository without too many problems.
You can add a new remote that is your old saved repository:
Then you can fetch all of the old history.
Then you can open up a history browser (e.g.
gitk --all
) to have a look at the old history.You can check out versions of missing files with a command such as:
The
old/master
refers to the master branch in your old repository, you can use the id of any branch or commit here, though.