2017-08-16 52 views
0

假設我有這些提交(字母是哈希數):如何將文件恢復到以前的承諾,但保持其他文件提交的最新

-a(initial commit) 
-b(implemented feature request affected foo.php and bar.php) 
-c(someone else's commit) 
-d(someone experimented on foo.php/bar.php and forgot to discard changes) 
-e(another commit) 
-f(latest commit) 

如何更改foo.php和bar.php到提交「c」期間的情況。 到目前爲止,我試過git reset cgit reset --hard c,但它改變了整個存儲庫。

另一種方法我試過到目前爲止是使回購和reset --hard c另一個克隆,然後我手動複製粘貼foo.php和bar.php到我的工作拷貝,然後我演出和推動改變遙控器。

回答

2

只需將文件恢復爲舊提交,並提交更改即可。

git checkout <old_commit_id> file_path 

例如 -

git checkout <hash_of_c> foo.php 
git checkout <hash_of_c> bar.php 
git add -u 
git commit -m "revert foo and boo" 
相關問題