简体   繁体   English

重置后从git恢复已删除的文件

[英]Recover deleted files from git after reset

Some time ago I made a mistake by merging a feature branch into the master branch (should have been develop). 前一段时间,我通过将功能分支合并到master分支(应该已经开发)而犯了一个错误。 I noticed this just after the merge and did a reset on the master branch. 合并后,我注意到了这一点,并在master分支上进行了重置。 This removed about 10 files from the master branch. 这从master分支中删除了大约10个文件。 Meanwhile I branched a new feature branch from develop and worked on this branch (also on the files deleted from master) and merged it back into develop. 同时,我从development分支了一个新的功能分支,并在该分支上工作(还处理了从master删除的文件),然后将其合并回development。

Today I merged the develop branch into master for a new release. 今天,我将develop分支合并为master,以发布新版本。 Unfortunately all files that were removed during the reset are missing in the master branch, new files that were added later are present. 不幸的是,在重置过程中删除的所有文件都在master分支中丢失,存在稍后添加的新文件。

I would like to merge the develop branch into master so that after the merge the master branch has the same files as the develop branch. 我想将dev分支合并到master分支中,以便在合并之后master分支具有与dev分支相同的文件。 How can I do this? 我怎样才能做到这一点?

I've tried rebasing the develop branch with the master branch but that only resulted in the files to be removed from the develop branch as wel. 我尝试用master分支重新建立development分支,但这只会导致文件从weld分支中删除。 I've been able to roll this back 我已经可以回滚了

You can check the git logs and identify the last commit which has all the files that you lost. 您可以检查git日志并确定包含所有丢失文件的最后一次提交。

git log

Once you identified the commit, copy the hash against the commit and run git checkout command. 确定提交后,将哈希复制到提交并运行git checkout命令。

git checkout COMMITHASH

after this your head will point to this commit which is having all the deleted files. 在此之后,您的头将指向具有所有已删除文件的提交。 You can merge your develop branch with current master state. 您可以将您的开发分支与当前主状态合并。

Note: not recommended according to me. 注意:不建议根据我。

Do you have these files in the develop branch ? 在develop分支中是否有这些文件? If so, they must be add by commit(s), right? 如果是这样,必须通过提交添加它们,对吗? Maybe you can make some patch by using 也许您可以使用进行一些修补

   git format-patch -s commit 

Save the patch to some other place. 将补丁保存到其他地方。 The checkout to master branch and apply it by using 检出到master分支并通过使用将其应用

   cat patch | git am

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

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