embedded-framework/doc/git/git-rebase.md
2023-09-02 23:11:34 +08:00

41 lines
1.5 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

## git rebase 合并多条 commit 记录
### PSgedit 不太好用,可以执行如下命令将编辑器修改为熟悉的 vim
```shell
git config --global core.editor "vim"
```
如图,我们有一些 commit 是比较凌乱的,现在希望将其整理为一条合适的 commit 提交到 远程仓库。
![git log](pic/p1.jpg)
我们需要将 day1 day2 add file 这三条记录合并为一条,执行
```shell
git rebase -i [commit]
```
**commit** 为你要合并的最后一条提交的下一个 commit
这里为 <font color=red>640f9a20c7bb7e9e3dfc76b089745d5c95818fed </font>
指令如下
```shell
git rebase -i 640f9a20c7bb7e9e3dfc76b089745d5c95818fed
```
![git rebase](pic/p2.jpg)
这里将弹出 vim 编辑窗口,可以看到有此次 rebase 涉及到三个 commit id我们选取需要 pick 的 commit id其余的参考下面注释添加 s 前缀,表示 commit 用于提交但是归并到 pick 的 commit 中。
:wq 保存,将进入下一个 vim 编辑界面
![:wq 保存](pic/p3.jpg)
将所有的 commit msg 编辑一个合适的归并 commit msg。
再次执行 :wq 保存即可。
![再次执行 :wq保存](pic/p4.jpg)
可以看到,我们将两条不希望留存的 commit 记录归并到了
![rebase后效果](pic/p5.jpg)
<font color=red>640f9a20c7bb7e9e3dfc76b089745d5c95818fed </font> 提交之中,并且,这样的操作并不会改变原本这个 commit id 的值。
PS: 具体 rebase 指令细节参考 ```git rebase --help```