合并 Git 个基本问题的分支
Merging a Branch on Git Basic Questions
这是 Git 上的一个非常初级的问题。我正在阅读有关分支和合并的书 here and website here。
我在 github 上有一个自述文件,我将它拉到我的本地机器上,在那里我创建了一个分支,更新自述文件并尝试将它合并回 main/origin。我似乎无法正确完成最后一步,我将不胜感激。
$ 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>
您想从分支 issue-1
返回到 master
或 main
。
您应该 git checkout master
或 git checkout main
而不是 git checkout origin
。
origin
是遥控器的名称(在您的例子中是 GitHub)。不是分支名称。
这是 Git 上的一个非常初级的问题。我正在阅读有关分支和合并的书 here and website here。
我在 github 上有一个自述文件,我将它拉到我的本地机器上,在那里我创建了一个分支,更新自述文件并尝试将它合并回 main/origin。我似乎无法正确完成最后一步,我将不胜感激。
$ 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>
您想从分支 issue-1
返回到 master
或 main
。
您应该 git checkout master
或 git checkout main
而不是 git checkout origin
。
origin
是遥控器的名称(在您的例子中是 GitHub)。不是分支名称。