git - 使用 SourceTree 在 Git 中检索已删除的存储

标签 git atlassian-sourcetree

我正在使用源代码树。我创建了一个包含多个更改的存储库,然后错误地删除了它。有办法找回它们吗?

最佳答案

根据之前的回答,这里有一个简单的序列:

打开终端窗口并进入存储库下的文件夹。然后:

git fsck | awk '{print $3}' > tmp.txt
cat tmp.txt | xargs git show > tmp2.txt

现在在编辑器中打开 tmp2.txt,找到您丢失的代码,并在其顶部找到 commit-id。然后应用代码:

git stash apply <commit id>
rm tmp.txt tmp2.txt

这救了我的命!我真的很感谢所有回答这个问题的人。我祝福 git 的创建者 Linus Torvalds 将删除的东西保存在 git 数据库中。天才!!

2021 年编辑:请注意,Windows 用户可以使用 Git Bash 执行相同操作.

关于git - 使用 SourceTree 在 Git 中检索已删除的存储,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17743078/

相关文章:

git - .gitignore 忽略文件的地方

git - 我可以强制 git branch --contains <tag> 不打印星号吗?

git - 所有现有文件在 sourcetree 中显示为未暂存文件

git - 在git中提交 "virtual"文件并使其

node.js - 成功的 npm 包发布未显示在 npm.js 上

git - 使用 Git 在特定时间或日期自动提交和推送

git - SourceTree - rebase - merge 期间的错误

eclipse - Atlassian SourceTree自定义 Action 对比

git - 将 SourceTree 连接到 Windows 上的 AWS CodeCommit

git 连接被放弃,致命的 : Could not read from remote repository