删除分支中间的提交 [英] Removing commit from middle of a branch

查看:158
本文介绍了删除分支中间的提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做了一些提交并将其推送到了我的远程回购站。其中一个我想删除。它只包含一个二进制文件,仅在该分支中提交时才更改。如何将它删除而不会对以后的提交造成影响?

I've made some commits and have pushed it to my remote repo. One of those I want to remove. It includes only one binary file, which was changed only in that commit in that branch. How to remove it without harm for later commits?

推荐答案

您可以使用 interactive(-i)

You can use interactive (-i) rebase to remove a previous commit.

$ git log                          # copy the target commit 

$ git rebase -i <target-commit>~1  # start rebase from the previous commit of target commit

编辑器将打开一个提交列表,每行一个。这些行中的每一行都以 pick 开头。 注释掉你的目标提交行(在目标提交行的开头放置)。

An editor will open with a list of commits, one per line. Each of these lines begins with pick. Comment out your target commit's line (Put # at the start of target commit line).

$ git rebase --continue      # repeat the command until finish rebase


$ b $

Now, you need force (-f) push to remote since git history is changed.

$ git push -f origin HEAD 

这篇关于删除分支中间的提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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