git命令commit了2次记录,需要合并成一次记录

操作本意是这样的,一个项目的一个bug问题,我先commit了一次,然后领导又发现有问题不规范,又让我再提交一下,我忘了用哪个–amend追加提交,而领导也不希望一个bug合入2笔代码,这个时候,我们就只能做合并2次commit的内容为一次了,
如果是合并2个commit的话,用这个

1.# HEAD~3 表示将近三次提交都合并,如果是将 2 次合并则为 HEAD~2
git rebase -i HEAD~2

回车以后,这个时候,看到的是一上对 COMMIT 信息的提示

pick 9ba5122 2017 年 8 月 2 日
pick c6da035 ~~

# Rebase 9b6bae1..c6da035 onto 9b6bae1 (2 commands)
#
# 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
# d, drop = remove commit
#
# These lines can be re-ordered; they are executed from top to bottom.
#
# If you remove a line here THAT COMMIT WILL BE LOST.
#
# However, if you remove everything, the rebase will be aborted.
#
# Note that empty commits are commented out

第一列对应的是 rebase 具体的操作,其含义如下:

pick(p)	git 会应用这个补丁,以同样的提交信息(commit message)保存提交
reword(r)	git 会应用这个补丁,但需要重新编辑提交信息
edit(e)	git 会应用这个补丁,但会因为 amending 而终止
squash(s)	git 会应用这个补丁,但会与之前的提交合并
fixup(f)	git 会应用这个补丁,但会丢掉提交日志
exec(x)	git 会在 shell 中运行这个命令
drop(d)	git 会移除这次 COMMIT

2.将第二个 pick c6da035 ~~~ 这一行修改成 squash c6da035 ~~~ ,使之与之前的提交合并。

保存之后可以看到下面的内容

This is a combination of 2 commits.
# This is the 1st commit message:

2017 年 8 月 2 日

删除无用配置,提高启动速度

1. 更新 zucchini-org
2. 增加 CHANGELOG 用来记录每次更新
3. 更新 plantuml 配置
   FIXED Can't find plantuml-jar-path
4. 增加 parinfer 配置,用来优化 lisp 的编写速度

# This is the commit message #2:

~~

# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# Date:      Tue Aug 1 10:24:44 2017 +0800
#
# interactive rebase in progress; onto 9b6bae1
# Last commands done (2 commands done):
"~/spacemacs/spacemacs.d/.git/COMMIT_EDITMSG" 36L, 1003C

3.wq键保存修改后的并且退出
这个时候会有两次的提交信息,进入insert模式把不需要的那次的提交信息删除了,然后按Esc键后冒号wq保存退出就好了
修改成正确的 commit 信息之后,用wq保存并退出,这个时候就修改好了
vim的一些操作:先按键盘的左上角的esc键,再按英文冒号键:进入输入命令模式(有些人是esc+回车)

最后再提交一下即可
4.git push …
部分参考:https://segmentfault.com/a/1190000021550369
https://www.cnblogs.com/laphome/p/11309834.html
https://www.jianshu.com/p/f10aa607a293

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值