我最近 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/