2013-02-01 149 views
4

GIT相當新,需要一點幫助。恢復Git錯誤

在Github上託管我的內容。昨晚我意識到我沒有把我的內容推到Github上,所以我打開了github mac客戶端,並在我的項目上做了提交/同步。它說我在主分支之前提交了2個。我很困惑...

1錯誤 - 所以我做了「混帳的復位 - 硬起源/主」,然後我同步了Github上。

第二天早上我打開筆記本電腦,然後打開netbeans,我所做的所有工作都不見了。我處於恐慌模式...

所以我在Google上搜索並找到this page,它描述瞭如何撤銷GIT重置。我很好地跟上了這一點,並重置爲之前的提交。 這裏是我的Git重新記錄:

ce8d01b [email protected]{0}: reset: moving to [email protected]{1} 
fcc0db9 [email protected]{1}: commit: front page 
ce8d01b [email protected]{2}: reset: moving to origin/master 
a6bda3a [email protected]{3}: commit: front page 
cde0712 [email protected]{4}: commit: Fixed Front Page Slider 
ce8d01b [email protected]{5}: commit: Fixed Company Scrolling. 
dd7b163 [email protected]{6}: commit: Work on company product and home page 
4cc4274 [email protected]{7}: commit: Added Company Page 
1ebed75 [email protected]{8}: commit (initial): initial 

我做的git後復位HEAD @ {1}我打開NetBeans和代碼仍然是不存在,所以我想也許我做了錯誤的。所以我又做了一次,但是這一次去了HEAD @ {2}。我現在在哪裏。

a6bda3a [email protected]{0}: reset: moving to [email protected]{3} 
ce8d01b [email protected]{1}: reset: moving to [email protected]{1} 
fcc0db9 [email protected]{2}: commit: front page 
ce8d01b [email protected]{3}: reset: moving to origin/master 
a6bda3a [email protected]{4}: commit: front page 
cde0712 [email protected]{5}: commit: Fixed Front Page Slider 
ce8d01b [email protected]{6}: commit: Fixed Company Scrolling. 
dd7b163 [email protected]{7}: commit: Work on company product and home page 
4cc4274 [email protected]{8}: commit: Added Company Page 
1ebed75 [email protected]{9}: commit (initial): initial 

但我仍然看不到我的代碼。還有什麼我需要做的嗎?

感謝您的幫助

+1

單位犯它有你的代碼?它看起來像它可能是'a6bda3a',但你說你看不到你的代碼?你是否嘗試過'git checkout @ {6.pm.yesterday}''或者類似的東西以回到特定的時間點? –

+0

好吧,從你的評論卡爾。如果我現在做一個git reset HEAD @ {4}。我需要做一個git checkout來查看代碼,或者在git重置後它是否應該正確填充? – DaveG

+0

爲什麼如此設置使用'HEAD @ {4}'語法?使用散列或我給出的基於時間的示例有什麼問題? –

回答

2

從你引用日誌,一個

git reset --hard a6bda3a 

應該恢復您的內容,因爲它是git reset --hard origin/master之前。

然後,如果GitHub branch is ahead,我會建議:

git pull --rebase 
# check everything is still working 
# git add and git commit if needed 
git push 
+0

VonC ...感謝您的幫助。我也試過這個......沒有工作。 – DaveG

+0

@DaveG你的意思是a6bda3a不是你在第一次'git reset --hard'之前犯的代碼?不要忘記這個命令刪除所有私人文件並重置索引。那麼你有沒有沒有承諾的工作? – VonC

+0

是的,我回到了a6bda3a,它不是代碼。我在想我有沒有承諾的工作......愚蠢的錯誤。我認爲有一種拯救恩典。 (原諒我,因爲我通常使用GUI而不是命令行)。我現在打開GITHUB GUI,它說我從18小時前開始提交不確定的提交。我會很樂意回覆那個。我只是不確定如何在那裏切換。我的選擇是2周前的提交:) – DaveG