git基于当前分支的顶部

时间:2020-11-29 23:46:01

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.

我正在尝试与我当前的分支进行交互的rebase。比如,我有一个修复错误的提交,我想在另一个提交上做一个“修复”。

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). I'll quite the editor and get:

(我的编辑器以“noop”开头,我相信这是git在用“noop”代替实际的错误消息)。我去找编辑:

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?

3 个解决方案

#1


4  

git-rebase -i is an operation that is applied to a number of commits.

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

So, if your current branch is

所以,如果你现在的分支是。

A-B-C-D

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

git变基-我头~ 3

This means "rebase three top commits on the current branch" and "start from commit HEAD - 3".

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

#2


0  

Maybe you want git rebase -i --autosquash origin/myBranchName?

也许你想要git rebase -i——autowa origin/myBranchName?

Argument of git-rebase is the point from where to start rewriting the history. It operates on the currently checked out branch.

git-rebase的论点是从哪里开始重写历史。它对当前签出的分支进行操作。

#3


0  

I guess your situation is as follows?

我猜你的情况是这样的?

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

with Af being the fixup-commit for A

用Af作为修正-提交A

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.

它可以向您显示交互式的选择/壁球视图,使您能够将A和Af一起压缩。

#1


4  

git-rebase -i is an operation that is applied to a number of commits.

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

So, if your current branch is

所以,如果你现在的分支是。

A-B-C-D

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

git变基-我头~ 3

This means "rebase three top commits on the current branch" and "start from commit HEAD - 3".

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

#2


0  

Maybe you want git rebase -i --autosquash origin/myBranchName?

也许你想要git rebase -i——autowa origin/myBranchName?

Argument of git-rebase is the point from where to start rewriting the history. It operates on the currently checked out branch.

git-rebase的论点是从哪里开始重写历史。它对当前签出的分支进行操作。

#3


0  

I guess your situation is as follows?

我猜你的情况是这样的?

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

with Af being the fixup-commit for A

用Af作为修正-提交A

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.

它可以向您显示交互式的选择/壁球视图,使您能够将A和Af一起压缩。