如何将Git的交互式rebase与仅限本地的存储库(没有远程/源)一起使用?

mcw*_*933 33 git branch rebase git-rebase remote-branch

我使用git作为本地源控制系统,主要用于历史和差异跟踪.我仍然希望使用rebase来对我将定期制作的WIP提交进行修复/压缩.当我尝试做的时候git rebase -i,我得到以下内容:

There is no tracking information for the current branch.
Please specify which branch you want to rebase against.
See git-rebase(1) for details

    git rebase <branch>

If you wish to set tracking information for this branch you can do so with:

    git branch --set-upstream-to=<remote>/<branch> MyBranch
Run Code Online (Sandbox Code Playgroud)

看来git不希望你在没有上游遥控器的情况下使用交互式rebase?我怎么做?

Séb*_*ans 30

git rebase -i简而言之,如果没有指定目标分支,将使git假设您正在尝试对您的分支跟踪的远程分支进行rebase.这就是错误消息提到遥控器的原因.

当你指定一个目标时,git将对该commit-ish进行 rebase :

git rebase -i <commit-ish>
Run Code Online (Sandbox Code Playgroud)


Mik*_*keW 18

所以简而言之 - 如果你有3个本地提交,你现在想要交互式地改变/压缩/等等它们:

git rebase -i HEAD~3
Run Code Online (Sandbox Code Playgroud)

(见塞巴斯蒂安的解释!)