[英]How to revert a folder to a particular commit by creating a patch
Here's my history for the folder 'somefolder'这是我的文件夹“somefolder”的历史记录
$ git log somefolder
commit 89cd
More changes to somefolder
commit ef47a
Updating somefolder and other stuff
commit e095
Bugs fixed in somefolder
I want to revert somefolder back to the 'Bugs fixed in some folder" commit.我想将某个文件夹恢复为“在某个文件夹中修复的错误”提交。
Since the second commit involved changes outside of somefolder, I don't want to revert this commit.由于第二次提交涉及某个文件夹之外的更改,因此我不想恢复此提交。
I guess the safest way would be to create a diff/patch between commit e095 and 89cd that applies just to some folder, and then apply that patch.我想最安全的方法是在提交 e095 和 89cd 之间创建一个仅适用于某个文件夹的差异/补丁,然后应用该补丁。 How can I do that?
我怎样才能做到这一点?
You can use git checkout to update your repository to a specific state.您可以使用git checkout将您的存储库更新为特定的 state。
git checkout e095 -- somefolder
As for your question about generating the diff, that would work too.至于您关于生成差异的问题,那也可以。 Just generate the diff to go from your current state back to
e095
:只需将当前 state 的差异生成到 go 回
e095
:
git diff 89cd..e095 -- somefolder
You can use git reset
to reset the index which will also include removing files that were added in more recent commits ( git checkout
on it's own doesn't do this):您可以使用
git reset
重置索引,其中还包括删除在最近提交中添加的文件( git checkout
不会这样做):
git reset e095 -- somefolder
However git reset
doesn't update the working copy and the --hard
option doesn't work with folders.但是
git reset
不会更新工作副本,并且--hard
选项不适用于文件夹。 So then use git checkout
to make the working copy the same as the index:那么然后使用
git checkout
使工作副本与索引相同:
git checkout -- somefolder
and then if you also want to remove any files added you also need todo:然后如果您还想删除添加的任何文件,您还需要执行以下操作:
git clean -fd somefolder
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.