git rebase 在当前分支之上

标签 git rebase

我正在尝试对我当前的分支进行交互式 rebase 。即,我有一个修复拼写错误的提交,我想在另一个提交之上进行“修复”。

有时这行得通。有时这会给出格式奇怪的错误消息,例如:

# git rebase -i
You asked me to rebase without telling me which branch you
want to rebase against, and 'branch.myBranchName.merge' in
your configuration file does not tell me, either. Please
specify which branch you want to use on the command line and
try again (e.g. 'git rebase <upstream branch>').
See git-rebase(1) for details.

If you often rebase against the same branch, you may want to
use something like the following in your configuration file:
    [branch "myBranchName"]
    remote = <nickname>
    merge = <remote-ref>
    rebase = true

    [remote "<nickname>"]
    url = <url>
    fetch = <refspec>

See git-config(1) for details.

如果我告诉 git 分支根据(当前分支) rebase ,它会失败:

# git rebase -i myBranchName

(我的编辑器以“noop”打开,我相信这是 git 告诉我“no op”而不是实际的错误消息)。我会相当编辑并得到:

Successfully rebased and updated refs/heads/myBranchName. 

如何在我的编辑器中查看当前分支中的更改,并将其标记为修正?

最佳答案

git-rebase -i 是应用于多个提交的操作。

所以,如果你当前的分支是

A-B-C-D

例如,你想 merge A 和 C 提交,你需要运行(假设 A 是最高提交)

git rebase -i HEAD~3

这意味着“对当前分支上的三个顶级提交进行 rebase ”和“从提交 HEAD - 3 开始”。

关于git rebase 在当前分支之上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13514200/

相关文章:

git - 允许 PR 构建验证构建而不发布工件

Gitkraken striketrough 分支名称

Git 强制推送语法, "-f"与 "+branch"

git - 为什么非裸远程的 `git push` 不是远程的 `git fetch` 的对偶

git - 从多个分支 rebase

Git rebase 过程被分离的头卡住了

git - 在交互式 rebase 之后,本地 Git 分支已经偏离原点

java - 如何在 JGit 中运行 "git rebase -i --root"?

git:如何重做 merge 冲突解决方案(在提交 merge 之前)?

git - rebase 未按预期运行