git - rebase 时排除提交

标签 git git-merge rebase git-rebase

我最近 merge 了一个尚未准备好进入 master 的功能。在没有意识到的情况下,我将坏主分支重新设置为另一个好的分支。

但现在我不知道如何从我的其他故事中删除那些糟糕的提交。

这是我的 git 日志文件

commit 15bb0d630f9b9cf59axxxxxxx8100d3a7302
Author: Moises Zaragoza <<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="0c61566d7e6d6b63766d4c74747474226f6361" rel="noreferrer noopener nofollow">[email protected]</a>>
Date:   Mon Jun 1 11:45:31 2015 -0400

    Some updates 


commit 3caf183afe3f5d7dcfxxxxxxxa239d44c8dfd11a
Author: Moises Zaragoza <<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="afc2f5ceddcec8c0d5ceefd7d7d7d781ccc0c2" rel="noreferrer noopener nofollow">[email protected]</a>>
Date:   Mon Jun 1 11:45:31 2015 -0400

    Some updates 

commit 3c6c81c7a3215fcdxxxxxxxb56a5540745c397
Author: Moises Zaragoza <<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="9cf1c6fdeefdfbf3e6fddce4e4e4e4b2fff3f1" rel="noreferrer noopener nofollow">[email protected]</a>>
Date:   Wed Jun 3 16:59:31 2015 -0400

    Bad Commit that should not be here 

最佳答案

如果您还没有推送代码,您可以进行交互式 rebase 并删除提交:

git rebase --interactive 3c6c81c7a3215fcdxxxxxxxb56a5540745c397^

您最终将得到一个具有提交历史记录的编辑器:

3c6c81c7a3215fcdxxxxxxxb56a5540745c397 Bad Commit that should not be here
3caf183afe3f5d7dcfxxxxxxxa239d44c8dfd11a Some updates 
15bb0d630f9b9cf59axxxxxxx8100d3a7302 Some updates 

如果你想删除commit 3c6c81c7a3215fcdxxxxxxb56a5540745c397,只需在交互式rebase中删除这一行并保存即可:

3caf183afe3f5d7dcfxxxxxxxa239d44c8dfd11a Some updates 
15bb0d630f9b9cf59axxxxxxx8100d3a7302 Some updates 

参见http://www.git-scm.com/book/en/v2/Git-Tools-Rewriting-History

关于git - rebase 时排除提交,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30646616/

相关文章:

git - 如何重写历史记录以便删除文件夹中所做的所有更改?

git - 修改使用 merge 以使用 rebases 的 git 主题分支的历史记录

eclipse - EGit 2.3 新增--no-ff 选项,如何使用?

git - 是否可以替换 git merge 算法?

不使用分支的 git rebase

git - 在 IntelliJ IDEA 中针对 origin/master 重新设置分支

javascript - chromecast 自定义接收器 - 播放列表在没有 "onLoad"动画的情况下推进媒体

git - 如何在 github 子目录中托管 Jekyll 博客?

git - 使 gh-pages 与 master 的最新提交保持同步

git rebase 分支与祖 parent