簡體   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