繁体   English   中英

与pygit2合并时,HEAD从原点/主节点发送

[英]HEAD detatched from origin/master when merging with pygit2

我正在使用pygit2合并项目的某些分支,但是每当合并它们时,我都会得到以下结果:

def avoid_walls(directions, board, snake):
<<<<<<< HEAD
return directions
=======
z = 1
moves = []
for direction in directions:
    new_x = snake[0][0] + dirs[direction][0]
    new_y = snake[0][1] + dirs[direction][1]
    if new_x >= 0 and new_x < len(board[0]) and new_y >= 0 and new_y < len(board):
        moves.append(direction)
return moves
>>>>>>> 357f58b6d1682760b2fa9bf7b2418da347ca353c

在我的代码中。 当我用“ git status”检查仓库时,我发现:

HEAD detached from origin/master
All conflicts fixed but you are still merging.
  (use "git commit" to conclude merge)

据我所知,我一切都做得很好,所以我无法弄清为什么HEAD分离了。 据我了解,当您检出特定的提交而不是分支时,HEAD是分离的,而我没有这样做:

# clone repo to local directory
repo = pygit2.clone_repository(my_repo, my_dir)

# checkout master branch (checked out by default, but just to be safe)
repo.checkout('refs/remotes/origin/master')

# merge with other branches
repo.merge(repo.branches['origin/branch1'].target)

# commit changes
index = repo.index
index.add_all()
index.write()
author = pygit2.Signature("ME", "me@domain.com")
commiter = pygit2.Signature("ME", "me@domain.com")
tree = index.write_tree()
oid = repo.create_commit('refs/heads/master', author, commiter, "init commit", tree, [repo.head.target, repo.branches['origin/branch1'].target])

#some tests i tried to fix the issue
repo.head.set_target(oid)
repo.apply(oid)

合并后,我是否会丢失某些东西来完成提交并解决此问题?

refs/remotes/origin/master不是分支。 所有分支refs/heads/开头:

if name.startswith('refs/heads/'):
    print('{} is a branch name'.format(name))
else
    print('{} is not a branch name'.format(name))

在这种情况下,因为它以refs/remotes/开头,所以它是一个远程跟踪名称 (Git文档通常将其称为远程跟踪分支名称 ,但是我认为这太误导了,因为它包含单词branch,即使它不是分支名称)。

当您签出远程跟踪名称,标签名称或任何不是分支名称的名称时,您实际上是在签出特定的提交,并且将获得一个分离的HEAD

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM