0

关于 Git rebase 的疑问

 2 years ago
source link: https://www.v2ex.com/t/808327
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

V2EX  ›  git

关于 Git rebase 的疑问

  JasonLaw · 2 小时 23 分钟前 · 393 次点击

我需要修改之前一个 commit 的 message,然后我找到了Changing git commit message after push (given that no one pulled from remote) - Stack Overflow一个回答,我不太理解回答中的以下这段话,请问是什么意思呢?

Note that if you edit your rebase 'plan' yet it doesn't begin the process of letting you rename the files, run:

git rebase --continue

4 条回复    2021-10-17 14:19:15 +08:00

AmoreLee

AmoreLee   2 小时 4 分钟前

操作一下你就明白了。

执行 git rebase -i HEAD~4

会出现一个页面,让你标记每个 commit 的顺序,是否需要修改信息等。也就是所谓的 ‘plan’,告诉 git 你想对这些提交干啥。

如果你设置好你的 ‘plan’, 但是 rebase 没开始,就执行 git rebase --continue 告诉 git 开始 rebase 就好了。


不过需要注意的是,一旦 rebase 就会改动你的提交记录,如果之前已经提交到远程,rebase 后再想 push 是会报错的。除非你强制推送,但如果别人已经拉取过你的远程仓库,那就会造成很多麻烦。如果只是本地仓库就无所谓了。

dangyuluo

dangyuluo   1 小时 55 分钟前

A<-B<-C<-D<-E<-F<-HEAD,你现在在 HEAD 上,发现 C 里面有个错误。你需要
```
git rebase -i C~1 # or git rebase -iB
```
然后修改 rebase 命令,把 C 那行的第一个动词改成 e,然后保存。这时候你就到了 C 提交之后的那一刻,修改好之后(我一般`git commit --amend`),再`git rebase --continue`,之后的 DEF 等 commit 就会自动回来,有冲突的话会停在冲突的地方。

rebase 还支持其他命令,自己玩玩就行

skiy

skiy   15 分钟前

@dangyuluo 请问一下,rebase 后,当前项目分支的 commit 就会有冲突了,不允许提交。这个要如何解决呢?

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK