【发布时间】:2016-02-06 03:41:35
【问题描述】:
我从不同的分支切换,所以我可以做一个推送。在进行结帐时,文件在我的编辑器中打开,这可能导致权限被拒绝错误。 git 是否丢失了我所有的文件?我不知道如何让他们回来。这就是我所做的 -
文件丢失是
js/Messages目录
templates/Messages目录
这些是在我进行 git 操作时在我的编辑器中打开的
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?
编辑:
我又运行了一个命令,输出如下。我不确定这是什么意思
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
我必须重新编写整个代码吗!?
【问题讨论】:
-
你说的是“本地提交的文件”。这意味着您在某个时候运行了“git commit”,对吗?这样您的文件就不会丢失,您只需要找到该提交的哈希值,就可以将它们取回。尝试运行
git reflog,它将显示您最近执行的操作(结帐、提交等),以及每个操作的提交哈希。然后对于每个看起来像您可能想要的哈希,运行git show (hash),例如git show 1da3053。这将向您显示该提交的日志消息和内容。 -
是的,我在某个时候承诺过。请看我的编辑。我看到了这些悬空提交和 blob。不知道如何恢复它们。奇怪的是 git reflog 没有向我显示丢失的最后一次提交。
-
对于悬空提交,您只需执行
git checkout (hash)即可恢复它们,现在您的工作目录包含该提交的内容,并且您的HEAD指向该提交。然后您可以通过简单地执行git branch (branchname)创建一个新分支,它将基于该提交创建一个新分支——并且该提交将不再是悬空的。当然,首先你要在悬空提交上运行git show (commit-hash)以查看它们是什么。 -
这是否适用于 blob 和提交?
-
Blob 只是单个文件的内容,这不是您要查找的内容。您似乎不太熟悉 blob 和提交之间的区别,所以gitguys.com/topics/… 可能对您以后不尝试恢复丢失的数据时有用。