当前位置: 代码网 > it编程>编程语言>其他编程 > git使用rebase删除某次提交的问题

git使用rebase删除某次提交的问题

2025年09月22日 其他编程 我要评论
git删除某次commit记录在git中,要删除某次commit记录有几种不同的实现方法:方法一:使用git rebase命令和~标记该方法适用于删除最近的几次commit记录。首先,使用以下命令查看

git删除某次commit记录

在git中,要删除某次commit记录有几种不同的实现方法:

方法一:使用git rebase命令和~标记

该方法适用于删除最近的几次commit记录。

首先,使用以下命令查看你需要删除的commit的记录

git log

找到你要删除的commit的哈希值(commit id)。

运行以下命令来使用git rebase命令删除commit记录(假设删除最近的一次commit)。

git rebase -i head~1

这将打开一个交互式的rebase窗口。找到要删除的commit记录所在的行,将其前面的pick改为drop。

pick abc1234 commit message 1
drop def5678 commit message 2 (to be deleted)

保存并关闭文件。

git将执行rebase操作并删除你在步骤3中指定的commit记录。

这里出现了一个问题,看一下错误

$ git rebase -i head~1
interactive rebase in progress; onto 52784b2
last commands done (2 commands done):
   pick abc1234 commit message 1
   drop def5678 commit message 2 (to be deleted)
next commands to do (2 remaining commands):
   drop 46b66b5 #1000049091 xx1
   pick 2df1056 #1000027181 xxx2
you are currently rebasing branch 'feature/dubhe-pay-platform-2.12.3-bak' on '52784b2'.

nothing to commit, working tree clean
the previous cherry-pick is now empty, possibly due to conflict resolution.
if you wish to commit it anyway, use:

    git commit --allow-empty

otherwise, please use 'git cherry-pick --skip'
could not apply c600123... #1000046509 门店标记二期需求

大致意思是 有一些提交记录中,没有任何的文件变动,问我们要不要保留这些空(无文件改动)的提交,按需选择即可,我选择的是

# 跳过当前无法自动合并的提交,并继续处理后续的提交
git cherry-pick --skip

看下暂存区是否有未添加的文件,如果有,使用以下命令添加到暂存区,并提交到本地仓库

git add .
git commit -m "rebase"

然后告诉git,已经处理完rebase了

git rebase --continue

最后强制推送到远程仓库即可, 注意,一定要强制推送,否则白改了

git push origin branch_name -force
# 简写
git push origin branch_name -f

撤销 rebase 修改

如果你在 git rebase 过程中遇到问题并希望中止 rebase,可以使用以下命令:

git rebase --abort

这个命令会将你的分支恢复到 rebase 开始之前的状态,撤销所有未完成的 rebase 操作。

总结

以上为个人经验,希望能给大家一个参考,也希望大家多多支持代码网。

(0)

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论

验证码:
Copyright © 2017-2025  代码网 保留所有权利. 粤ICP备2024248653号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com