意外合并到错误的分支中.有没有办法删除这些不需要的文件? [英] Accidentally merged in wrong branch to mine. Is there a way to remove these unwanted files?

查看:104
本文介绍了意外合并到错误的分支中.有没有办法删除这些不需要的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不小心将一个同事分支合并到我正在处理的分支中.从那时起,我已经进行了几次提交,因此理想情况下,我不想恢复到分支在合并之前的状态.但是,我还没有做过任何改变他文件的事情.

I accidentally merged a co-workers branch into the branch I was working on. I've made several commits since then so ideally I don't want to revert to the state the branch was before the merge. However, I haven't done anything that has altered his files.

有没有办法从我的网站上删除他分支的文件?

Is there a way I can remove his branch's files from mine?

(对不起,我是git的新手-希望我掌握了该术语).

(Sorry, I am new to git - hope I've got the terminology down).

推荐答案

这里最简单,最安全的选择也许是还原您之前提交的合并提交.为此,请使用git log在历史记录中找到合并提交,并记录该提交的SHA-1哈希.然后,执行以下操作:

Perhaps the easiest and safest option here would be to revert the merge commit which you made a few commits ago. To do this, find the merge commit in your history using git log, and record the SHA-1 hash of that commit. Then, do the following:

git revert -m 1 <SHA-1>

此处<SHA-1>是您要撤消的合并提交的哈希. -m 1选项告诉Git恢复到第一个父级,该父级是合并所基于的分支,应该是您的分支.

Here <SHA-1> is the hash of the merge commit you want to undo. The -m 1 option tells Git to revert to the first parent, which is the branch on which the merge originated, which should be your branch.

这篇关于意外合并到错误的分支中.有没有办法删除这些不需要的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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