為簡單起見,讓我們創建一個只有兩個提交的存盤庫:
mkdir somedir
cd somedir
git init
echo hello > somefile
git add somefile
git commit -m 'first'
echo world >> somefile
git commit -am 'second'
為清楚起見,此時git log --oneline回傳
fd5b1ce (HEAD -> master) second
f621ab9 first
我想要得到的是以下內容
xxxxxxx (HEAD -> master) third
fd5b1ce second
f621ab9 first
with somefileinthird具有與 in 相同的somefile內容first。
我當然可以做git cherry-pick master~(這里master是fd5b1ce)并完全解決沖突first,但也許有更清潔的方法?
uj5u.com熱心網友回復:
提交回滾另一個?
這似乎很適合git revert
git revert <second commit>
但這適用于第二次提交的所有檔案(正在恢復)
在第三個中與
somefile第一個中的 somefile 具有相同的內容。
如果您只需要還原一個檔案,請使用git restore.
git restore -SW -s=<first commit> -- somefile
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/426174.html
