将git rebase在当前分支的顶部。

3

我正在尝试对我的当前分支进行交互式变基。也就是说,我有一个修复错字的提交,我想将其作为“fixup”放在另一个提交之上。

有时候它工作正常,但有时候会给出奇怪格式的错误消息,比如:

# 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要将分支(当前分支)合并,它会失败并显示以下信息:
# git rebase -i myBranchName

(我的编辑器打开了'noop',我认为这是git告诉我'no op'而不是实际的错误消息)。我将退出编辑器并获得:

Successfully rebased and updated refs/heads/myBranchName. 

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

你目前在哪个分支?"myBranchName"? - Vi.
你已经推送了你想要修复的提交吗? - Vi.
我的当前分支是myBranchName。不,我还没有推送我想要修复的提交。 - mikemaccana
3个回答

4

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

如果你当前的分支是

A-B-C-D

并且你想合并A和C提交,你需要运行以下命令(假设A是最新的提交):

git rebase -i HEAD~3

这意味着“在当前分支上重定位最近的三个提交”并且“从提交HEAD-3开始”。


没问题。如果是这样,你可以接受答案(打勾)。 - Adam Adamaszek
抱歉让您久等了! - mikemaccana

0

我猜你的情况是这样的?

-A-B-C----D----(HEAD)
  \----Af

假设Af是修复提交A的提交记录

你希望它变成

-(A+Af)-B-C-D--(HEAD)

针对这种情况,我会尝试以下方法:

>> rebase <Af>          # where <Af> is the SHA1 of commit Af

你的历史将会变成

-A-Af-B-C-D----(HEAD)

然后

>> rebase -i <A>^       # A^ is the commit that came before A

它应该显示交互式的挤压视图,使您可以将AAf挤压在一起。


0
也许你想要使用 git rebase -i --autosquash origin/myBranchName 命令?这个命令的参数是指定重写历史记录的起点,它会在当前所在的分支上操作。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接