Git rebase 命令行操作

Git rebase 命令行操作

1.创建新分支(在需要进行rebase的分支上开辟新分支)

git checkout -b rebase

 

2.进行rebase操作(master作为变基的节点,也可以根据需要选择commit的ID)

git rebase -i master

 

3.进行变基操作(根据需要更改commit信息的合并与删除)

注意:如果需要删除必须使用 d,drop 进行

pick 89cc90c xx
pick 5090cb0 11
pick 88a66e3 22
pick 41e7968 asdf

# Rebase d0482a2..41e7968 onto d0482a2 (4 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.
#
"~/Desktop/test-git/.git/rebase-merge/git-rebase-todo" 23L, 705C

 

进行VIM操作

pick 89cc90c xx
squash 5090cb0 11
squash 88a66e3 22
squash 41e7968 asdf

# Rebase d0482a2..41e7968 onto d0482a2 (4 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.
#
-- INSERT --

注意:等一行操作必须是pick 不然会告诉你重新编辑

esc退出编辑  使用 :wq保存

 

4.重新编辑commit

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

xx

# This is the commit message #2:

11

# This is the commit message #3:

22

# This is the commit message #4:

asdf

# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
"~/Desktop/test-git/.git/COMMIT_EDITMSG" 32L, 649C

可以使用 dd 进行 整行删除

new commit

# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# Date:      Tue Sep 4 16:02:24 2018 +0800
#
# interactive rebase in progress; onto d0482a2
# Last commands done (4 commands done):
#    squash 88a66e3 22
#    squash 41e7968 asdf
# No commands remaining.
# You are currently rebasing branch 'rebase' on 'd0482a2'.
#
# Changes to be committed:
#       modified:   README.md
#
~

esc退出编辑  使用 :wq保存

 

5.成功后

 1 file changed, 4 insertions(+), 4 deletions(-)
Successfully rebased and updated refs/heads/rebase.

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值