我可以在GIT中进行部分恢复吗? [英] Can I do a partial revert in GIT

查看:107
本文介绍了我可以在GIT中进行部分恢复吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



全文 $ b $是否可以在多文件提交中仅恢复单个文件或文件中的某些更改? b我犯了一堆文件。之后的一些提交将会保留无名(JACK !!!)的文件将一个文件复制到他的存储库并提交了几个文件,覆盖了我所做的一些更改。我想恢复一个被破坏或更好的文件,进入并恢复该文件中的两个更改。这将是一个单独的撤销提交,因为它被拉和推。

解决方案

您可以恢复提交而不创建一个新的一个通过添加'--no-commit'选项。这会将所有还原的文件保留在暂存区域中。从那里,我会执行软重置并添加我真正想要的更改。对于工作流示例:

  git revert< sha-of-bad-commit> --no-commit 
git reset //这将它们从暂存区域中取出
<编辑坏文件以使其看起来像是它应该的,如果需要的话>>
git add<坏档案>
git checkout。 //这样擦除了所有不想要的回复仍然在工作副本中徘徊
git commit


Is it possible to revert only a single file or certain changes in a file in multi file commit?

Full story I committed a bunch of files. A number of commits later someone who will remain nameless (JACK!!!) copied a file into his repository and committed several files, overwriting some of the changes I did. I want to revert the one file that got clobbered or better yet, go in and revert two changes in that file. This will have to be a separate revert commit since it was pulled and pushed.

解决方案

You can revert the commit without creating a new one by adding the '--no-commit' option. This leaves all the reverted files in the staging area. From there, I'd perform a soft reset and add in the changes I really wanted. For an example workflow:

git revert <sha-of-bad-commit> --no-commit
git reset   // This gets them out of the staging area
<edit bad file to look like it should, if necessary>
git add <bad-file>
git checkout . // This wipes all the undesired reverts still hanging around in the working copy
git commit

这篇关于我可以在GIT中进行部分恢复吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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