【发布时间】:2022-01-18 16:21:13
【问题描述】:
这是一个关于 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>
【问题讨论】:
-
origin是远程的别名,而不是分支的名称。您可能应该使用git checkout main或git switch -
标签: git git-branch