簡體   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