2017-03-06 115 views
0

我有本地分支。我寫新文件,更換其他文件並錯誤地刪除一個文件。承諾。恢復舊本地提交中刪除的文件

再次編寫代碼(新/更改文件)。承諾。

沒有推。

我想在我的第一次提交中刪除刪除文件。
我不想修改第二次提交來恢復已刪除的文件。

任何人都可以幫助我嗎?我沒有想法。

我的解決辦法:

git rebase -i HEAD~2  
[Change for first commit 'pick' to 'edit'] 
git reset HEAD^  
[Revert deleted file] 
[Add other files and commit] 
git rebase --continue 
+0

讓我們看看是否理解你:要恢復刪除的文件在一定的承諾,而再重新添加它。 – CodeWizard

+0

是的,我不想創建第三次提交或修改第二次提交 –

回答

1
git checkout <id-of-commit1>~1 path/to/the/deleted/file 
git commit --fixup <id-of-commit1> 
git rebase -i --autosquash 
[it opens editor, check that the rebase plan is correct, exit the editor to proceed] 
+0

我們應該使用「git rebase -i --autosquash」,而不是「git rebase -i --autosquash 」 ? –

+0

@YShinkarev這取決於。通常,如果你使用簡單的分支/克隆,默認情況下工作正常,所以你不需要指定更多的參數來重定義。但是,如果你想要更精確或不尋常的東西,你可以。 – kan