【问题标题】:Git Rebase on a Specific Remote, Branch, and Commit基于特定远程、分支和提交的 Git Rebase
【发布时间】:2022-10-20 21:08:53
【问题描述】:

情况是:

我有一个没有设置遥控器的本地 git repo。我想为特定分支添加一个遥控器,我相信我可以这样做:

git remote add New_Remote -t -f {New_Remote_Branch} {Repo}

然后,我想将我的本地 git repo 重新定位到 New_Remote_Branch 的 HEAD 上,而是到它的特定提交上。我已经阅读了文档,并且看到了 --onto 选项,但是对于如何将其定位到特定的远程并提交有点困惑。我在测试这个概念和找到语法时遇到了麻烦。我相信我正在寻找类似的东西:

(来自本地 repo 目录)

git rebase New_Remote/New_Remote_Branch --onto {New_Remote_Branch_Specific_Commit_id}

【问题讨论】:

  • Git 不在乎提交是在远程分支上还是在本地分支上,甚至不在任何分支上:对于{New_Remote_Branch_Specific_Commit_id},您只需提供相关的提交 ID,您就应该做好准备。首先确保您git remote update 以确保您拥有任何远程参考的本地副本。
  • ...和往常一样,如果您不确定自己做的是否正确,您始终可以对存储库的副本进行操作,直到您按照您想要的方式工作。

标签: git rebase git-remote


【解决方案1】:

git rebase 的完整语法是:

git rebase --onto $new_upstream $old_upstream $branch_to_rebase

它将接受 old_upstream 和 branch_to_rebase 之间的所有提交,并在 new_upstream 之上重新创建它们。最后,“branch_to_rebase”引用将指向最新的重新创建的提交。

因此,在您的情况下,您的命令将类似于:

git rebase --onto $specific_commit_id master your_branch

(假设您要复制自 master 以来创建的分支上的所有提交)

【讨论】:

    猜你喜欢
    • 2021-09-17
    • 1970-01-01
    • 1970-01-01
    • 2020-04-04
    • 2023-01-13
    • 2016-05-03
    • 2019-11-17
    • 2015-05-02
    • 2020-03-12
    相关资源
    最近更新 更多