如何通过创建补丁将文件夹恢复到特定提交 [英] How to revert a folder to a particular commit by creating a patch

查看:129
本文介绍了如何通过创建补丁将文件夹恢复到特定提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的文件夹'somefolder'的历史记录。

  $ git log somefolder 

commit 89cd
对某些文件夹的更多更改

提交ef47a
更新某些文件夹和其他内容

提交e095
在某些文件夹中修复的错误

我想将某些文件夹还原为'在某个文件夹中修复的错误'提交。



由于第二次提交涉及到某些文件夹以外的更改,因此我不想恢复此提交。



我想最安全的方法是创建提交e095和89cd之间的差异/补丁,只适用于某个文件夹,然后应用该补丁。我该怎么做?

您可以使用 git checkout 将您的资料库更新至特定状态。

  git checkout e095  -  somefolder 



<至于你关于生成的问题差异,这也会起作用。只需生成diff即可从当前状态返回到 e095

  git diff 89cd..e095  -  somefolder 


Here's my history for the folder '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. How can I do that?

解决方案

You can use git checkout to update your repository to a specific 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:

git diff 89cd..e095 -- somefolder

这篇关于如何通过创建补丁将文件夹恢复到特定提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆