git rebase -i HEAD~2 将提交合并到上一次未审核的提交

本文介绍了如何使用 `git rebase -i HEAD~2` 合并最近两次提交到上一次未审查的提交中,详细阐述了rebase交互式编辑过程,包括将提交融合(squash)及修改提交信息的步骤。此外,还提供了另一种通过 `git commit --amend` 和 `git push` 修改未审核提交的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

git add ./

git commit -m"oooooooo"

git rebase -i HEAD~2 (索引从1开始,同理若更改前n次的commit,此处改为n即可)

显示如下:

pick 238fedf balabala。
pick 941fb81 oooooooo

# Rebase 3c79056..941fb81 onto 3c79056
#
# Commands:
#  p, pick = use commit
#  r, reword = use commit, but edit the commit message
#  e, edit = use commit, but stop for amending
#  s, squash = use commit, but meld into previous commit
#  f, fixup = like "squash", but discard this commit's log message
#  x, exec = run command (the rest of the line) using shell
#
# If you remove a line here THAT COMMIT WILL BE LOST.
# However, if you remove everything, the rebase will be aborted.


修改 pick 941fb81 oooooooo

为: s 941fb81 oooooooo

ctrl+x

Y

enter

显示如下:

# This is a combination of 2 commits.
# The first commit's message is:

balabalabala
Change-Id: I484981f3db67e10090802331ee0067353a710c7e
# This is the 2nd commit message:
oooooooo
Change-Id: If2ce5e712d5bfa6352bab9b2067f4adf3c913811


# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
# Not currently on any branch.
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#       modified:   AndroidManifest.xml


将第二个提交信息注释掉:

#oooooooo
#Change-Id: If2ce5e712d5bfa6352bab9b2067f4adf3c913811

Ctrl+x


git push HEAD:balabala 即可。


法2:

提交了第一个记录,未审核,需修改。

1. 修改。

2. git add ./

3. git commit --amend

4. git push origin HEAD:refs/changes/460546

460546 为上次提交的change。







评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值