繁体   English   中英

当前分支顶部的git rebase

[英]git rebase on top of current branch

我正在尝试针对我当前的分支进行交互式反思。 也就是说,我有一个修正错误的提交,我想在另一个提交之上做一个'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告诉我'没有op'代替实际的错误信息)。 我会编辑得到:

Successfully rebased and updated refs/heads/myBranchName. 

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

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

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

A B C D

并且你想要,例如,合并A和C提交,你需要运行(给定A是最高提交)

git rebase -i HEAD~3

这意味着“在当前分支上重新设置三个顶级提交”和“从提交HEAD - 3开始”。

也许你想要git rebase -i --autosquash origin/myBranchName

git-rebase的争论是从哪里开始重写历史的重点。 它在当前签出的分支上运行。

我想你的情况如下?

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

AfA的fixup-commit

而你希望它成为

-(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在一起。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM