簡體   English   中英

Git從一個遠程分支推送到另一個遠程分支

[英]Git Push From One Remote Branch To Another Remote Branch

我正在使用三個分叉版本的源代碼。 僅供參考我將名稱更改為不透露身份/回購。 以下是它的布局:

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)

這里, 上游是最新和穩定版本的原始源代碼。 Origin是我的分叉版本。 ABC是別人的版本。

ABC有一個分支機構,我從那里開始工作。 我想然后進行更改並推送到我的倉庫(原產地),然后提交拉動請求。 ABC的分支被稱為“abc / obs-noise”。

根據git狀態:

git status
HEAD detached from abc/obs-noise

當我對所述文件進行更改時,我承諾:

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的菜鳥,但我幾乎可以肯定我做的一切都是正確的,它看起來就是那樣。 我想知道我在哪里找到我的提交? 我不想重做我所有的工作。

首先,你坐在一個獨立的HEAD上。 這意味着您剛剛進行的任何提交都不會移動原始分支指針。 如果更改活動分支,那么你很有可能丟失這些提交,這就是為什么git push不會推送任何新內容:原始分支指針尚未被移動。

首先,當您開始處理任何遠程分支時,您應該創建一個對應於給定遠程分支的本地分支。 采用

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

然后,當您進行提交時,此<local_branch_name>將提前跟隨您的提交行。 當您需要將給定的提交行推送到遠程分支時,請使用

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

如果需要為不同的遠程控制器創建多個開發線,則應創建多個相應的本地分支並單獨推送它們。

你不能從分離的HEAD推出。 唯一的方法是

git checkout -b newbranch e8eeea3
git push origin origin_branch_name

有關詳細信息,請參閱此處

從@Torek輸入后進行編輯:可能存在用例,您想要推動分離的頭部。 詳情請見此處 見下面的評論。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM