git rebase -i commitID
commitID
相当于根,所以调整的是下游的commitID
命令行处理
1.准备数据
文本内容
version1
version2
version3
version4
6d9da8c (HEAD -> master) version4
77f4597 version3
2c9a2d1 version2
8f53d32 version1
2.git rebase 2c9a2d1
变基到version2
的commit
我们想要调整version3
和version4
,这时就需要git rebase version2
这个命令的实质内容是将HEAD
到version3
branch,进行变基到version2
上,在变基过程中可以进行修改.
输出内容为:
第一列是对该commit的操作,下面的注释中有解释
第二列是commitID
第三列是提交时的信息
pick 77f4597 version3
pick 6d9da8c version4
# Rebase 2c9a2d1..6d9da8c onto 2c9a2d1 (2 commands)
#
# Commands:
# p, pick <commit> = use commit
# r, reword <commit> = use commit, but edit the commit message
# e, edit <commit> = use commit, but stop for amending
# s, squash <commit> = use commit, but meld into previous commit
# f, fixup <commit> = like "squash", but discard this commit's log message
# x, exec <command> = run command (the rest of the line) using shell
# b, break = stop here (continue rebase later with 'git rebase --continue')
# d, drop <commit> = remove commit
# l, label <label> = label current HEAD with a name
# t, reset <label> = reset HEAD to a label
# m, merge [-C <commit> | -c <commit>] <label> [# <oneline>]
# . create a merge commit using the original merge commit's
# . message (or the oneline, if no original merge commit was
# . specified). Use -c <commit> to reword the commit message.
#
# 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.
#
我们这里只对他们进行顺序的调整
pick 6d9da8c version4
pick 77f4597 version3
3.处理冲突
因为有冲突,此时终端了rebase的交互操作,弹出信息,让我们先处理
error: could not apply 6d9da8c... version4
Resolve all conflicts manually, mark them as resolved with] 27L, 1136C written
"git add/rm <conflicted_files>", then run "git rebase --continue".
You can instead skip this commit: run "git rebase --skip".
To abort and get back to the state before "git rebase", run "git rebase --abort".
Could not apply 6d9da8c... version4
Auto-merging src/main/java/com/test
CONFLICT (content): Merge conflict in src/main/java/com/test
此时的测试文件内容也变成了
version1
<<<<<<< HEAD
version2
=======
version2
version3
version4
>>>>>>> 6d9da8c... version4
手动处理冲突为
version2
version3
version4
并保存提交
git add ./
git rebase version4
跳出输入提交注释的文本框
version4
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# interactive rebase in progress; onto 2c9a2d1
# Last command done (1 command done):
# pick 6d9da8c version4
# Next command to do (1 remaining command):
# pick 77f4597 version3
# You are currently rebasing branch 'master' on '2c9a2d1'.
#
# Changes to be committed:
# modified: src/main/java/com/test
#
同理继续处理version3
的冲突
成功
[detached HEAD e262a42] version3
1 file changed, 2 insertions(+), 2 deletions(-)
Successfully rebased and updated refs/heads/master.
idea图形界面处理
参考:
https://blog.youkuaiyun.com/claroja/article/details/114953017