2014-04-26 78 views
2

我一直在爲這個大型商業產品(即源代碼)開發附加組件。這個我正在開發的插件位於該文件夾內: ~/dev/project/addons/my_addon如何使用嵌入式GIT進行GIT重置

爲了保持可維護性,我在此文件夾中創建了一個git回購。 我使用git commit工作並保存了最重要的東西。

昨天晚上我錯過了核心產品中的一項功能,我想我可以自己構建這個功能併發送補丁。 這是我沒有:

cd ~/dev/project 
git init 
git add * 
git commit -m 'init' 

我認爲這將是很好的,因爲如果我不小心就會使程序崩潰時我可以只git reset --hard併爲創建補丁文件的我可以只混帳補丁。

昨天我工作了6個小時,包括這個補丁,同時我在自己的插件中做了一些編碼。今天早上我犯了一個很大的錯誤。 我想重置我在項目文件夾中所做的更改。但是我在附加組件中做了這個,我已經失去了30多個小時的工作。

~/dev/project我有以下git的歷史:

[email protected]:Commercial_License_3.73% git log 
commit 40f4059dd05311997b5093077e69e89535b1ecb6 
Author: Stolas <[email protected]_domain.org> 
Date: Fri Apr 25 23:31:57 2014 +0200 

    init 
[email protected]:Commercial_License_3.73% git reflog 
40f4059 [email protected]{0}: checkout: moving from master to 40f4059 
40f4059 [email protected]{1}: reset: moving to 40f4059 
2f1ce07 [email protected]{2}: commit: stash, I want my **** files back 
40f4059 [email protected]{3}: commit (initial): init 
[email protected]:Commercial_License_3.73% git status 
HEAD detached at 40f4059 
Changes not staged for commit: 
    (use "git add <file>..." to update what will be committed) 
    (use "git checkout -- <file>..." to discard changes in working directory) 
    (commit or discard the untracked or modified content in submodules) 

    modified: addons/my_addon (new commits, modified content, untracked content) 

Untracked files: 
    (use "git add <file>..." to include in what will be committed) 

    .history 
    Sessions/25042014.log 
    Sessions/25042014--23_36_16.log 
    Sessions/26042014--00_17_28.log 

no changes added to commit (use "git add" and/or "git commit -a") 
[email protected]:Commercial_License_3.73% 

凡在我的~/dev/project/addons/my_addon我有以下的git歷史:

[email protected]:my_addon% git log 
commit eff5291b50ad09970c6386ef4deaa70f6e8a0270 
Author: Stolas <[email protected]_domain.org> 
Date: Sat Apr 26 08:27:34 2014 +0200 

    Revert "Revert "First setup nearly done."" 

    This reverts commit 6567b65523898e625b8ded8b058885ca51f2aae4. 

commit 6567b65523898e625b8ded8b058885ca51f2aae4 
Author: Stolas <[email protected]_domain.org> 
Date: Sat Apr 26 08:27:14 2014 +0200 

    Revert "First setup nearly done." 

    This reverts commit b3c55d3f736f15c78f71ada5f0bf5ae46cf8dd71. 

commit b3c55d3f736f15c78f71ada5f0bf5ae46cf8dd71 
Author: Stolas <[email protected]_domain.org> 
Date: Wed Apr 23 22:48:39 2014 +0200 

    First setup nearly done. 

commit b8c234a4cf52e89367d49788594442d8142624d8 
Author: Stolas <[email protected]_domain.org> 
Date: Sat Apr 19 09:01:36 2014 +0200 

    Start Env 

commit cc4d0b7add2ed852043e549716481207ec7ef13b 
Author: Stolas <[email protected]_domain.org> 
Date: Sat Apr 19 09:00:24 2014 +0200 

    Start Envoirment button 

commit 92a2ac263b58adf8265d8edb4e14c075ee7b0ad1 
Author: Stolas <[email protected]_domain.org> 
Date: Sat Apr 19 08:58:13 2014 +0200 

    Setup 
[email protected]:my_addon% git reflog 
eff5291 [email protected]{0}: reset: moving to HEAD^ 
11bce53 [email protected]{1}: commit: dialog 
eff5291 [email protected]{2}: revert: Revert "Revert "First setup nearly done."" 
6567b65 [email protected]{3}: revert: Revert "First setup nearly done." 
b3c55d3 [email protected]{4}: commit: First setup nearly done. 
b8c234a [email protected]{5}: commit: Start Env 
cc4d0b7 [email protected]{6}: commit: Start Envoirment button 
92a2ac2 [email protected]{7}: commit (initial): Setup 
[email protected]:my_addon% git status 
On branch master 
Changes not staged for commit: 
    (use "git add <file>..." to update what will be committed) 
    (use "git checkout -- <file>..." to discard changes in working directory) 

    modified: libs/my_addon_main.py 

Untracked files: 
    (use "git add <file>..." to include in what will be committed) 

    .idea/ 
    libs/my_addon_paint.py 
    libs/my_addon_msging.py 
    template/dialog.xml 

no changes added to commit (use "git add" and/or "git commit -a") 

我想我可以通過使結帳解決這個問題爲init提交較低的git,但它似乎重置除了我的git文件夾的一切。 如何重置git中的git到昨天?或者還原我的還原(s)

我拼命想要回來的文件是libs/my_addon_main.py,因爲大部分工作都在此文件中。

回答

3

git reset --hard恢復取決於幾個因素(從您的嵌套的git倉庫,在那裏你錯誤地做了一個reset --hard內檢查):

  • 更改(現已遺失)已經承諾:
    你可以看到看到一個git reflogrecover from there

  • 您的更改已添加到索引,但從未提交。
    您仍然可以使用this answer根據git fsck --unreachable --no-reflogs --no-cache HEAD找到它們。不承諾不添加

  • 你的變化:
    您的IDE可以提供文件的自己的本地歷史(如this answer

  • 如果一切都失敗了,檢查備份(如Mac上的TimeMachine)或磁盤恢復工具(如Recuva mentioned in this answer

+0

一切都失敗了,我覺得我可能只是需要採取的打擊。並將此作爲提醒,在您睏倦時永遠不要使用GIT,並每小時製作所有文件編輯的影子副本。 – Stolas

+0

@Stolas是的,或定期製作包,如在http://stackoverflow.com/a/1251717/6309(它只生成*一個*文件,比文件夾深層複製更容易管理) – VonC

+0

它失敗了,因爲你沒有是否展示了您的更改,還是存在另一個問題? – user3426575