简体   繁体   English

我在 git 中一次提交了 10 个文件,但现在我怎样才能只恢复其中的 2 个

[英]I had commit 10 files at a time in git but now how can I revert only 2 of them

I had pushed those 10 commit files in git and pushed them in master branch on github but now I have to revert 2 file of them back to the previous version.As far as I know if I revert back with commit Id all 10 files will get reverted but I don't want that.我已经在 git 中推送了这 10 个提交文件,并将它们推送到 github 的 master 分支中,但现在我必须将其中的 2 个文件恢复到以前的版本。据我所知,如果我用提交 ID 恢复,所有 10 个文件都会得到恢复,但我不希望那样。 Can anyone help me out?谁能帮我吗?

you can do:你可以做:

git revert <your-commit-id>
git reset --mixed HEAD~
git add <files-to-be-reverted>
git commit -m 'revert the two files'
git reset --hard

explanation:解释:

git revert - reverts the whole commit, all the 10 files will be reverted git revert - 恢复整个提交,所有 10 个文件都将被恢复

git reset --mixed HEAD~ - takes the index back to the previous commit but leaves the work tree as is git reset --mixed HEAD~ - 将索引返回到上一个提交,但保留工作树原样

git add - only add the changes you want before committing git add - 在提交之前只添加你想要的更改

git commit - create a new commit git commit - 创建一个新的提交

git reset --hard - clean-up your work tree and index from unwanted changes git reset --hard - 清理您的工作树和索引以防止不需要的更改

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

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