with PyGit2 I am trying to replicate the behavior of the "git checkout (commit)" command, where (commit) is ...">

Replication "git checkout <commit> with PyGit2

I am trying to replicate the behavior of the "git checkout (commit)" command, where (commit) is a reference to a specific commit, not a branch name.

When using this "HEAD" command, the repository indicates a commit (detached head) and working directory in the same state as in this commit.

At the moment, I managed to make the HEAD repository points commit with PyGit2:

def go(self, repo_name, version):
    repo = pygit2.Repository(bdd[repo_name])
    #commit = repo.revparse_single(version)
    #repo.reset(version, pygit2.GIT_RESET_HARD)
    repo.set_head(pygit2.Oid(hex=version))
    print repo.head_is_detached

My problem is that I cannot find how to roll back a working directory such as CLI Git. I tried using:

  • repo.checkout_head(): it does nothing in the working directory.
  • repo.checkout(): failure with GitError: X conflicts prevent checkout

Is there any way to reproduce this behavior without using Repository.reset(ref, pygit2.GIT_RESET_HARD)?

+4
1

git read-tree -um HEAD $target && git update-ref HEAD $target; pygit2, -, , , , , , git. , , , reset HEAD .

+2

Source: https://habr.com/ru/post/1676807/


All Articles