简体   繁体   English

当前分支顶部的git rebase

[英]git rebase on top of current branch

I am attempting an interactive rebase against my current branch. 我正在尝试针对我当前的分支进行交互式反思。 Ie, I have a commit that fixes a typo, that I'd like to make into a 'fixup' on top of another commit. 也就是说,我有一个修正错误的提交,我想在另一个提交之上做一个'fixup'。

Sometimes this works. 有时这很有效。 Sometimes this gives a strangely formatted error message like: 有时,这会给出一个奇怪格式的错误消息,例如:

# 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.

If I tell git the branch to rebase against (the current branch) it fails with: 如果我告诉git分支反对(当前分支)它失败了:

# git rebase -i myBranchName

(my editor opens up with 'noop', which I believe is git telling me 'no op' in place of an actual error message). (我的编辑打开'noop',我相信git告诉我'没有op'代替实际的错误信息)。 I'll quite the editor and get: 我会编辑得到:

Successfully rebased and updated refs/heads/myBranchName. 

How can I see the changes in my current branch in my editor, and mark it as fixup? 如何在编辑器中查看当前分支的更改,并将其标记为fixup?

git-rebase -i is an operation that is applied to a number of commits. git-rebase -i是一个应用于许多提交的操作。

So, if your current branch is 所以,如果你当前的分支是

ABCD A B C D

and you want to, for instance, merge A and C commits, you need to run (given A is the top commit) 并且你想要,例如,合并A和C提交,你需要运行(给定A是最高提交)

git rebase -i HEAD~3

This means "rebase three top commits on the current branch" and "start from commit HEAD - 3". 这意味着“在当前分支上重新设置三个顶级提交”和“从提交HEAD - 3开始”。

Maybe you want git rebase -i --autosquash origin/myBranchName ? 也许你想要git rebase -i --autosquash origin/myBranchName

Argument of git-rebase is the point from where to start rewriting the history. git-rebase的争论是从哪里开始重写历史的重点。 It operates on the currently checked out branch. 它在当前签出的分支上运行。

I guess your situation is as follows? 我想你的情况如下?

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

with Af being the fixup-commit for A AfA的fixup-commit

And you want it to become 而你希望它成为

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

For this scenario I would try the following: 对于这种情况,我会尝试以下方法:

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

your history would become 你的历史会变成

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

And then 然后

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

It sould show you the interactive pick/squash view that enables you to squash A and Af together. 它可以显示交互式选择/壁球视图,使您可以将AAf在一起。

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

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