将子目录永久重置为特定的过去状态 [英] Permanently reset subdirectory to specific past state

查看:55
本文介绍了将子目录永久重置为特定的过去状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在git仓库中,我有一个子目录,我想将其重置为过去的特定状态(较早的提交).是否可以撤消对特定子目录中文件的所有提交?我认为没有提交可以同时将更改应用于此子目录中的文件以及同时位于其他位置的文件的提交.但是,如果可以对不在此目录中的 不受影响的文件进行提交,那将是一件好事吗?

In a git repository I have a subdirectory that I want to reset to a specific state in the past (an earlier commit). Is it possible to undo all commits on files in a specific subdirectory? I think there are no commits that apply changes to files within this subdirectory and on files located elsewhere at the same time. But it would be nice if it were possible to leave commits on files unaffected that are not located in this directory?

我不需要删除历史记录.签出旧状态,删除子目录的当前内容,并在其位置复制并提交旧状态将是没有问题的.但是最终可能会有一种更优雅的方式( gitonic ).

I don't need to remove the history. It would be no problem to checkout the old state, remove the current content of the subdirectory, and copy and commit the old state in its place. But eventually there may be a more elegant (gitonic) way.

推荐答案

使用git checkout功能应用于子目录的最简单方法.然后登台并提交:

The simplest way to do it to use the ability of git checkout to be applied on a subdirectory. Then stage and commit:

git checkout <old-SHA1> -- path/to/subdir
git add -A path/to/subdir
git commit -m "reverted files in path/to/subdir to what it was at <old-SHA1>"

这篇关于将子目录永久重置为特定的过去状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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