git 合并/删除 commit

先使用git log 查看commit记录,

localhost:appro icourt$ git log
commit cb44e8fea0c201cfeb8cfce7433ab4e65ef70e50 (HEAD -> test)
Merge: b397d25 3fffafc
Author: 张晓阳 <xiaoyangzhang1990@163.com>
Date:   Thu Feb 22 19:24:16 2018 +0800

    冲突

commit 3fffafcd01411740096892c0c222d2c188471098 (origin/zhangxy-appro-comment-fixbug, zhangxy-appro-comment-fixbug)
Author: 张晓阳 <xiaoyangzhang1990@163.com>
Date:   Thu Feb 22 19:22:02 2018 +0800

    评论没有通知流程发起人

commit b397d253b8b013c62114c206e0eaf5ec97706ea7
Author: 张晓阳 <xiaoyangzhang1990@163.com>
Date:   Thu Feb 22 19:20:16 2018 +0800

    评论没有通知流程发起人

commit 13de34376dc4880cd787da790f7c083908c18abb (origin/test)

执行git rebase -i HEAD~3(这里是你要合并的commit的个数),会出现下面的内容:

pick cb44e8fea0c    add center style indent  
pick 3fffafcd014    add center style  
pick b397d253b8b    add center style  
# Rebase 150a643..2fad1ae onto 150a643  
#  
# 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  
#  
# 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

从第2行开始的提交,将pick 改为squash,
当前我们只要知道 pick 和 squash 这两个命令即可。

  • pick 的意思是要会执行这个 commit

  • squash 的意思是这个 commit 会被合并到前一个commit

输入wq 保存并退出,再使用git log 会发现commit已经合并成了一个新的commit。
如果合并后有冲突,修改冲突后可以使用git rebase --continue ,使合并进行下去。
注意:如果这个过程中有操作错误,可以使用 git rebase --abort来撤销修改,回到没有开始操作合并之前的状态。


如果要删除某个commit,比如3fffafcd01411740096892c0c222d2c188471098:
1. 首先找到此次提交之前的一次提交的commit 7753f40d892a8e0d14176a42f6e12ae0179a3210
2. 执行如下命令
git rebase -i 7753f40d892
会出现如上图所示的内容,将要删除的commit的pick 改为drop,输入wq 保存并退出即可,使用git log 查看提交历史,会发现那个commit已经没有 了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

每天进步一点_点

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

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

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

打赏作者

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

抵扣说明:

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

余额充值