2014-04-26 35 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