简体   繁体   English

如何还原提交的特定文件?

[英]How can I revert specific files of a commit?

I have pushed a commit that modified files file1, file2, file3, file4, file5. 我推送了一个修改文件file1,file2,file3,file4,file5的提交。
I have decided that the logic is wrong and as part of the commit I modified some APIs in files2,file3. 我认为逻辑是错误的,并且作为提交的一部分,我修改了files2,file3中的一些API。
What I want to do is somehow revert the changes localy for files2,files3 and and fix the rest of the files correctly. 我想要做的是以某种方式还原files2,files3的更改区域设置,并正确修复其余文件。
So start my fix having as base the original version of the files2,files3 but the latest of the rest. 因此,以文件2,文件3的原始版本为基础,但以其余版本的最新版本为基础开始我的修复。
How can I do that? 我怎样才能做到这一点?

Easiest way to do this: 最简单的方法:

# get the version of the file from the given commit
git checkout <commit> path/to/file

In my case: 就我而言:

git checkout b1cdc80fffe381eb3938e7b7f337d6550ffbd199 /MyProjects/AndroidCameraAPI/app/src/main/java/info/androidhive/androidcameraapi/MainActivity.java

Then modified my code and did the commit again. 然后修改我的代码,然后再次提交。

NOTE: The commit has I have used in my example was the stable version, in which I wanted to revert back. 注意:我在示例中使用的提交是稳定版本,在该版本中我想还原。

The easiest way is to soft reset your commit (this will keep the changes in your files but not committed). 最简单的方法是软重置您的提交(这会将更改保留在文件中,但不会提交)。 Discard the changes for the files2 and files 3 (this will set them back to the previous commit). 放弃对文件2和文件3的更改(这会将它们设置为上一次提交)。

Git reset documentation Git重置文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM