使用 git,如何将跟踪分支合并回远程源/HEAD?

发布于 2024-12-26 04:52:30 字数 664 浏览 2 评论 0原文

我让自己陷入了本地仓库的混乱之中。 长话短说,我有一份副本远程仓库的;我在本地存储库中创建了一个名为“my_branch”的分支;我曾多次承诺工作。然后我将分支推送到远程仓库。这是我的本地存储库图...(因为我已将 my_branch 推送到远程,这也是远程的样子)。

--C0--------------C4--  (local master) 
      \
       --C1-C2-C3--     (local my_branch)

然后我决定尝试重新建立基础,但我想我完全搞砸了。我还尝试执行 git reset --hard ,我想我又损坏了我的本地存储库。所以我决定从一个干净的地方开始。我从远程存储库中获取了 my_branch 以下

然后我从远程检查了 origin/my_branch 。 (我现在看到我的 GUI 工具 GitX 中有一个“分离的 HEAD”。)现在...如何将此分支与远程上的 origin/HEAD 又名 origin/master 合并?

I got myself into a little bit of a local repo mess. Long story short, I had a copy of a remote repo; I created a branch called 'my_branch' in my local repo; I committed work a few times. I then just pushed the branch to the remote repo. Here's my local repo diagram...(since I've pushed my_branch to the remote, this is what remote looks like too).

--C0--------------C4--  (local master) 
      \
       --C1-C2-C3--     (local my_branch)

I then decided to try to rebase, but I think I totally messed up. I also tried to do git reset --hard and I think I corrupted my local repo some more. So I decided to start from a clean place. I grabbed my_branch from the remote repo following this.

I then checked out origin/my_branch from remote. (I now see that I have a "detached HEAD" in my GUI tool GitX.) Now...how do I merge this branch with origin/HEAD aka origin/master on remote?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

尽揽少女心 2025-01-02 04:52:30

在您要跟踪工作的位置创建一个分支

git checkout -b new-branch HEAD

现在您可以查看其他分支并合并或重新设置它们的基础。

要获取您尚未跟踪的远程分支的本地分支:

git checkout -t origin/some-branch

现在只需上推分支即可。您很可能需要用力推动

git push -f origin some-branch

Make a branch right where you are to get that work tracked

git checkout -b new-branch HEAD

Now you can check out other branches and merge or rebase them.

To get a local branch for a remote one that you are not tracking yet:

git checkout -t origin/some-branch

Now just push up the branches. Most likely you will require a force push

git push -f origin some-branch
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文