git 使用 rebase 删除某次 提交

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 操作。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

java叶新东老师

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值