gpt4 book ai didi

Git 从一个远程分支推送到另一个远程分支

转载 作者:太空狗 更新时间:2023-10-29 13:51:03 26 4
gpt4 key购买 nike

我正在使用源代码的三个分支版本。仅供引用,我更改了名称以不透露身份/ repo 协议(protocol)。这是它的布局方式:

MyMBP:~/Documents/_library$ git remote -v

abc https://github.com/abc/_library (fetch)
abc https://github.com/abc/_library (push)
origin https://github.com/123/_library.git (fetch)
origin https://github.com/123/_library.git (push)
upstream https://github.com/source/_library (fetch)
upstream https://github.com/source/_library (push)

这里,upstream 是原始源代码,是最新的和稳定的版本。起源是我的 fork 版本。 ABC是别人的版本。

ABC 有一个分支机构,我从那里 pull 出来工作。然后我想进行更改并推送到我的 repo (来源),然后提交 pull 请求。 ABC 上的分支称为“abc/obs-noise”。

根据 git 状态:

git status
HEAD detached from abc/obs-noise

当我对上述文件进行更改时,我 promise :

git commit
[detached HEAD e8eeea3] OBSERVATION NOISE ADDITION TO THE MONITORS
1 file changed, 23 insertions(+), 11 deletions(-)

然后我 git 推送(据说是我的来源)。

git push -u origin abc/obs-noise
Counting objects: 5, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (5/5), done.
Writing objects: 100% (5/5), 733 bytes | 733.00 KiB/s, done.
Total 5 (delta 4), reused 1 (delta 0)
remote: Resolving deltas: 100% (4/4), completed with 4 local objects.
To https://github.com/123/_library.git
* [new branch] abc/obs-noise -> abc/obs-noise

但是,我查看了我的存储库...没有 abc/obs-noise,也没有此提交的任何证据。我是 git 的菜鸟,但我几乎可以肯定我做的每件事都是正确的,看起来就是这样。我想知道在哪里可以找到我的 promise ?我不想重做我所有的工作。

最佳答案

首先,你坐在一个独立的 HEAD 上。这意味着您刚刚进行的任何提交都不会移动原始分支指针。因此,如果您更改事件分支,您很有可能会丢失这些提交,这就是 git push 不推送任何新内容的原因:原始分支指针尚未移动。

首先,当您开始在任何远程分支上工作时,您应该创建一个本地 分支,对应于给定的远程分支。使用

git checkout -b <local_branch_name> <remote>/<branch>

然后当你提交时,这个 <local_branch_name>将提前遵循您的提交行。当您需要将给定的提交行推送到远程分支时,使用

git push <remote> <local_branch_name>:<remote_branch_name>

如果你需要针对不同的远程有多条开发线,你应该创建几个相应的本地分支并分别推送。

关于Git 从一个远程分支推送到另一个远程分支,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49055534/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com