git checkout后,Git丢失了本地提交的文件 [英] Git lost local commited files after git checkout

查看:235
本文介绍了git checkout后,Git丢失了本地提交的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从其他分支切换,因此可以进行推送.结帐时,文件已在我的编辑器中打开,这可能导致权限被拒绝错误.git是否丢失了我的所有文件?我不知道如何让他们回来.这是我所做的-文件丢失了 js/Messages 目录 templates/Messages 目录这些是在我执行git操作时在编辑器中打开的

I was switching from a different branch so I can do a push. While doing the checkout the files were open in my editor which may have caused a permission denied error. Did git lose all my files? I dont know how to get them back. Here is what i did - The files are lost are js/Messages directory templates/Messages directory These were open in my editor when i was doing git operations

C:\Users\***\Documents\myproject>git pull
Password for 'https://********@bitbucket.org':
Already up-to-date.

C:\Users\***\Documents\myproject>git checkout paymentmodule
error: cannot stat 'www/js/Messages': Permission denied
error: cannot stat 'www/js/Messages': Permission denied
error: cannot stat 'www/templates/Messages': Permission denied

C:\Users\***\Documents\myproject>git checkout paymentmodule
Switched to branch 'paymentmodule'

C:\Users\***\Documents\myproject>git push origin paymentmodule
Password for 'https://******@bitbucket.org':
To https://*******@bitbucket.org/********/myproject.git
 ! [rejected]        paymentmodule -> paymentmodule (non-fast-forward)
error: failed to push some refs to 'https://********@bitbucket.org/********/myproject.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

//THIS STEP WAS A MISTAKE
C:\Users\***\Documents\myproject>git fetch origin paymentmodule
Password for 'https://********@bitbucket.org':
From https://bitbucket.org/***********/myproject
 * branch            paymentmodule -> FETCH_HEAD

//This was what i wanted to do so I did it without reverting my previous step
C:\Users\***\Documents\myproject>git fetch origin paymentmodule:tmp
Password for 'https://**********@bitbucket.org':
From https://bitbucket.org/*******/myproject
 * [new branch]      paymentmodule -> tmp

C:\Users\***\Documents\myproject>git rebase tmp
First, rewinding head to replay your work on top of it...
warning: unable to access 'www/templates/Messages/.gitattributes': Permission denied
warning: unable to access 'www/templates/Messages/.gitattributes': Permission denied
warning: unable to access 'www/templates/Messages/.gitattributes': Permission denied
warning: unable to access 'www/templates/Messages/.gitattributes': Permission denied
Applying: Implement chat services
warning: unable to access 'www/templates/Messages/.gitattributes': Permission denied
Using index info to reconstruct a base tree...
.git/rebase-apply/patch:63: trailing whitespace.
For instructions on this, start with the
.git/rebase-apply/patch:586: trailing whitespace.
#
.git/rebase-apply/patch:588: trailing whitespace.
#
.git/rebase-apply/patch:613: trailing whitespace.

.git/rebase-apply/patch:759: trailing whitespace.

warning: unable to access 'www/templates/Messages/.gitattributes': Permission denied
warning: squelched 348 whitespace errors
warning: 353 lines add whitespace errors.
Falling back to patching base and 3-way merge...
error: cannot stat 'www/templates/Messages': Permission denied
error: Failed to merge in the changes.
Patch failed at 0001 Implement chat services
The copy of the patch that failed is found in: .git/rebase-apply/patch

When you have resolved this problem, run "git rebase --continue".
If you prefer to skip this patch, run "git rebase --skip" instead.
To check out the original branch and stop rebasing, run "git rebase --abort".

//This was a mistake too
C:\Users\***\Documents\myproject>git rebase --skip

C:\Users\***\Documents\myproject>git rebase --abort
No rebase in progress?

我又用以下输出运行了一条命令.我不确定这是什么意思

I ran one more command with the following output. I am not sure what this means

C:\Users\***\Documents\myproject>git fsck --no-reflog
Checking object directories: 100% (256/256), done.
dangling blob 8860babe2931ea1e9dbafaa589e7c4feb19f14c7
dangling commit 1da3053dbe12d11e4ae65dc3a2ba720c9b272b7b
dangling commit cd03cd391e3447be272d3b8307ddb49cd3de1189
dangling blob c9648cae0b45ef174fa88aa5ad6b9008085a9766
dangling blob 2bc76e285d27d6979cf47148711e7c91379910c8
dangling blob 410f4c2f02192a56a9d4c0f01e847d85276799b4
dangling commit 60b1d2f1e2b7f8bfa42d4d2f49857a1b66db8575
dangling blob 949297fe49f427065fe0e74568af852e2796cc19
dangling commit 50d44e0896b10d461629fc5bffe60ee26996d433
dangling commit a8d4aa02b375cb3e04b90033a1a9d17697f6583d
dangling commit f5b5c1a66f450010f30c352caa3baa2f5a3b6576
dangling blob 5af70169556610abe956f748dc25af77494cc06e
dangling blob 981d6a55406d8b2ec63f0952ac65ad1afc893d8a
dangling commit d61db3516d2bbaf24efcf3fe9b644823bdc4a7ff

我是否必须再次编写整个代码!?

Do i have to write the entire code again!?

推荐答案

经过长时间的讨论,事实证明,您先前的提交(带有日志消息实施聊天服务"的消息仍在reflog中可见.)在问题中说不是,但是您只是想念它而已.)因此,您需要做的(并且已经做过,正如我从聊天中所知道的那样)是:

After a long discussion in chat, it turns out that the your earlier commit (with log message "Implement chat services" was still visible in reflog. (You had said in the question that it wasn't, but you simply missed seeing it). So what you need to do (and have already done, as I know from chat) is:

git reflog

reflog 中大约十行,您将看到"a8d4aa0 HEAD @ {12}:提交:实现聊天服务".因此,您需要的提交哈希为 a8d4aa0 .现在您可以轻松地做到:

About ten lines down in reflog, you'll see "a8d4aa0 HEAD@{12}: commit: Implement chat services". So the commit hash you needed was a8d4aa0. Now you can simply do:

git checkout -b new-branch-name a8d4aa0

现在,您的提交在新分支上是安全的,并且可以根据需要进行合并或重新建立基础.

Now your commit is safe on a new branch, and ready to be merged or rebased as needed.

顺便说一句,也可以通过 git fsck --no-reflog 找到它;您刚刚说不幸的是,这些提交是旧的提交,我认为在我失去的提交之前就已经摇摇欲坠了",您放弃得太早了.这是您发布的 git fsck --no-reflog 输出中的代码行:

By the way, it was also findable via git fsck --no-reflog; you just gave up too soon when you said "unfortunately these commits are old commits which i think were craeted way before the ones i lost". Here's the line from the git fsck --no-reflog output you posted:

dangling commit a8d4aa02b375cb3e04b90033a1a9d17697f6583d

如果您已运行 git show a8d4aa02b375cb3e04b90033a1a9d17697f6583d ,您将找到自己的提交.

If you had run git show a8d4aa02b375cb3e04b90033a1a9d17697f6583d, you would have found your commit.

课程:寻找丢失的提交内容时,永不放弃.永远不要投降.(感谢 Galaxy Quest !)

Lesson: When looking for lost commits, never give up. Never surrender. (Thanks, Galaxy Quest!)

这篇关于git checkout后,Git丢失了本地提交的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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