這是一個關于 Git 的非常初級的問題。關于分支和合并,我正在關注這本書here和網站here。
我在 github 上有一個自述檔案,我將它拉到我的本地機器上,在那里我創建了一個分支,更新自述檔案并嘗試將它合并回主/源。我似乎無法正確完成最后一步,我將不勝感激。
$ git add README.md
# Creates a commit
$ git commit -m 'first commit of the day'
# Pushes the commit to github - no issues
$ git push
# Create and checkout a branch called issue-1
$ git branch issue-1
$ git checkout issue-1
在這一點上,我用額外的一行文本更新了自述檔案,比如“hello world”
# Assume I am still on the branch, I commit my changes
$ git commit --all -m "Completed issue; issue 1 closed"
# Now i check out the main portion of my project that i want to merge my
# changes into and I merge this into my main project origin.
$ git checkout origin
# Note: switching to 'origin'.
# You are in 'detached HEAD' state. You can look around, make experimental
# changes and commit them, and you can discard any commits you make in
# this state without impacting any branch.....
$ git merge issue-1
# Updating 0ad9cb3..8f0455d
# Fast-forward
# README.md | 1
# 1 file changed, 1 insertion( )
這實際上并沒有將我的更改合并到主專案中。如果我嘗試將其推回 github:
$ git push
# fatal: You are not currently on a branch.
# To push the history leading to the current (detached HEAD)
# state now, use
git push origin HEAD:<name-of-remote-branch>
uj5u.com熱心網友回復:
您想從分支回傳issue-1到master或main。
你應該做git checkout masterorgit checkout main而不是git checkout origin。
origin是遠程的名稱(在您的情況下是 GitHub)。不是分支的名稱。
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/387345.html
