【问题标题】:is a rebase enough when the remote advance?远程推进时,rebase 就足够了吗?
【发布时间】:2023-01-24 15:35:54
【问题描述】:

我有以下情况

 origin/master, master
|
some_commit
|
|  * HEAD-> thebranch, origin/thebranch
|  * some other commit
|  * some third commit
|/
* the last common commit

我不打算向 thebranch 添加任何提交,我只是在使用它。

现在我已经收到通知,分支的开发人员可能已经将其重新定位到 master 的顶部并向其添加了一些提交

问题

我的问题是在这种情况下我应该如何进行?

我猜

我正在考虑做

git fetch origin thebranch

然后将我的本地分支重新设置为 master

然后合并它?但这会产生合并提交吗? 我对如何进行感到困惑。

【问题讨论】:

    标签: git


    【解决方案1】:

    由于您没有主动使用该分支并且没有进行代码更改,因此您可以简单地将本地分支重置为远程分支并从那里继续使用它。这是变基或以其他方式更改远程分支历史记录的危险之一,如果人们检查了它,他们必须以某种方式回到远程分支的正轨。

    为此,只需获取分支并重置即可。您不想对分支进行更改,因此合并或变基没有意义。您只想将指针移动到新提交。

    git fetch origin thebranch # update your local copy of the remote branch
    git switch thebranch       # make sure you're on your local branch
    git reset origin/thebranch # resets the current branch to what's currently in origin/thebranch
    

    根据您的情况,您可能需要通过将 --hard 添加到重置命令来进行硬重置。

    【讨论】:

      猜你喜欢
      • 2011-03-08
      • 1970-01-01
      • 2011-01-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-09-23
      相关资源
      最近更新 更多