簡體   English   中英

為什么 rebase 在 GitHub 中將其他人的提交添加到我的 pr

[英]Why rebase add other's commit to my pr in GitHub

我搜索過類似的問題,例如使用 git rebase 意外地將其他人的提交添加到我的 PR 中 答案只是提供了一種從 pr 中刪除不需要的提交的方法,但我仍然不知道為什么會這樣。

這些是重現我的問題的命令,但我不確定是否適用於其他人。

>>> (main) git log --oneline --graph -5
* fa9a315 
* e52240c
* 25c40fb
* 9ceb4b0
* ed40e2c
>>> (main) git checkout ed40e2c
>>> (@ed40e2c) git switch -c test-rebase
>>> (test-rebase) echo "foo" >> ./test.txt
>>> (test-rebase) git commit -am "test message"
>>> (test-rebase) git push -u origin test-rebase
>>> (test-rebase) git branch -vv | grep test-rebase
* test-rebase  6c0f33e [origin/test-rebase] test message
>>> (test-rebase) // create a pr in GitHub
>>> (test-rebase) git rebase main
>>> (test-rebase ⇣1⇡5) git pull -r
>>> (test-rebase ⇡4) git push
>>> (test-rebase) // now my pr has other's commits, and I'm also the coauthor of those commits
>>> (test-rebase) git log --oneline --graph test-rebase origin/test-rebase main origin/main
* 8bd227f (HEAD -> test-rebase, origin/test-rebase) message-4
* 938935c message-3
* 4080d9d message-2
* 8dbd5cd message-1
* 6c0f33e test message
| * fa9a315 (origin/main, origin/HEAD, main) message-4
| * e52240c message-3
| * 25c40fb message-2
| * 9ceb4b0 message-1
|/  
* ed40e2c

我想我明白發生了什么。

所以....首先,你在添加一個提交后推送分支,對吧? 你把它設置為上游。 所以,你有這個:

XXXX test message (HEAD -> test-rebase, origin/test-rebase)
ed40e2c whatever commit on that commit

然后,你在main之上變基......所以你最終得到:

* XXXX' test message (HEAD-> test-rebase)
* fa9a315 blahblah (main)
* e52240c blahblah
* 25c40fb blahblah
* 9ceb4b0 blahblah
| * XXXX  test message (origin/test-rebase)
|/
* ed40e2c blahblah

然后你運行git pull -r這就是你搞砸的地方,因為你正在重新設置來自main的提交,這些提交已經是你已經推送的分支之上的分支的一部分。 這就是為什么您的 PR 包括您正在談論的那些提交。

我認為你應該做git pull -r而不是git push -f這樣你就可以將你剛剛重新定位的main分支替換為你的 PR 的舊分支。

暫無
暫無

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

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