您如何修复错误的合并,并将您的良好提交重播到固定合并上? [英] How do you fix a bad merge, and replay your good commits onto a fixed merge?

查看:9
本文介绍了您如何修复错误的合并,并将您的良好提交重播到固定合并上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在几次提交前不小心将不需要的文件(filename.orig,同时解析合并)提交到我的存储库,直到现在我才注意到它.我想从存储库历史记录中完全删除该文件.

I accidentally committed an unwanted file (filename.orig while resolving a merge) to my repository several commits ago, without me noticing it until now. I want to completely delete the file from the repository history.

是否可以重写更改历史记录,以便 filename.orig 从未添加到存储库中?

Is it possible to rewrite the change history such that filename.orig was never added to the repository in the first place?

推荐答案

如果您的情况不是问题中描述的情况,请不要使用此方案.此秘籍用于修复错误的合并,并将您的良好提交重播到固定合并上.

虽然 filter-branch 会做你想做的,但它是一个相当复杂的命令,我可能会选择用 git rebase 来做这个.这可能是个人喜好.filter-branch 可以在一个稍微复杂的命令中完成,而 rebase 解决方案是一次执行等效的逻辑操作.

Although filter-branch will do what you want, it is quite a complex command and I would probably choose to do this with git rebase. It's probably a personal preference. filter-branch can do it in a single, slightly more complex command, whereas the rebase solution is performing the equivalent logical operations one step at a time.

试试下面的食谱:

# create and check out a temporary branch at the location of the bad merge
git checkout -b tmpfix <sha1-of-merge>

# remove the incorrectly added file
git rm somefile.orig

# commit the amended merge
git commit --amend

# go back to the master branch
git checkout master

# replant the master branch onto the corrected merge
git rebase tmpfix

# delete the temporary branch
git branch -d tmpfix

(请注意,您实际上并不需要临时分支,您可以使用分离的 HEAD"来做到这一点,但您需要记下 git commit --amend<生成的提交 ID/code> 步骤提供给 git rebase 命令而不是使用临时分支名称.)

(Note that you don't actually need a temporary branch, you can do this with a 'detached HEAD', but you need to take a note of the commit id generated by the git commit --amend step to supply to the git rebase command rather than using the temporary branch name.)

这篇关于您如何修复错误的合并,并将您的良好提交重播到固定合并上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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