【问题标题】:Merging a Branch on Git Basic Questions在 Git 基本问题上合并分支
【发布时间】: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 maingit switch -

标签: git git-branch


【解决方案1】:

您想从分支issue-1 回到mastermain

您应该使用git checkout mastergit checkout main 而不是git checkout origin

origin 是远程的名称(在您的情况下是 GitHub)。不是分支的名称。

【讨论】:

  • 感谢thchpRichard Smith。这两个答案正是我想要的
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-06-24
  • 1970-01-01
  • 1970-01-01
  • 2023-03-06
  • 1970-01-01
相关资源
最近更新 更多