为了简单起见,让我们创建一个只有两个提交的存储库:
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
somefile
在third
中具有与first
中的somefile
相同的内容。
我当然可以做git cherry-pick master~
(这里是fd5b1ce
),完全支持first
来解决冲突,但是也许有一种更干净的方法?
发布于 2022-02-15 23:42:06
再犯一次?
这似乎很适合git还原
git revert <second commit>
但是,这适用于第二次提交(正在恢复)中的所有文件。
第三位是
somefile
,第三位的内容与第一位的somefile相同。
如果只需要还原一个文件,请使用git restore
。
git restore -SW -s=<first commit> -- somefile
https://stackoverflow.com/questions/71137925
复制