极客油画

在开发中,开发者可能对于某个功能的代码提交了多次,当需要将多个提交的commit合成一个commit的时候,就需要用到git rebase,俗称“变基”

实现方案:

  1. git log 查看多次提交历史

  2. git rebase -i HEAD~3 或 git rebase -i commitId (这个commitId是需要合同的commits的前一个commit节点的ID)

  3. 接下来会弹出一个vim窗口,并提示你该如何处理这些commits 如果要修改最近一次提交的信息,就这样做:

$ git rebase -i HEAD~1
# 之后,在弹出的界面中,将pick改为r。(p,r,s,d非常有用,e,f,x没有什么用)
# 改好之后,使用:wq命令保存
p 6ba0c4b 改为微服务的模式

# Rebase 4100caa..6ba0c4b onto 4100caa (1 command)
#
# 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
  1. 3之后会跳出一个弹窗,提示输入commit消息,以覆盖之前的。 写好之后,使用:wq命令保存退出就可以了。

本文发表于 0001-01-01,最后修改于 0001-01-01。

本站永久域名「 jiavvc.top 」,也可搜索「 极客油画 」找到我。


上一篇 « 下一篇 »

赞赏支持

请我吃鸡腿 =^_^=

i ysf

云闪付

i wechat

微信

推荐阅读

Big Image