GitPython icon indicating copy to clipboard operation
GitPython copied to clipboard

Reference error during commit

Open kai-kzh opened this issue 8 years ago • 4 comments

I am seeing following error during repo.index.commit.

OSError: Reference at 'refs/heads/master' does already exist, pointing to u'f746fc427841706fd2ba4302b99c7ae6eb135ab8', requested was 'f428c16e68aa324f24e222269c95f5c24a38db43'

After this error, file has been committed to this repository, if I do a git clone, I can see updated file. But git log will not show this update.

This is a repository only contains one text file which is around 500k. This is not always happen.

I am wondering what is this log indicating and how to prevent it. Thanks for your attention.

kai-kzh avatar Aug 25 '17 18:08 kai-kzh

Gitpython version is 2.0.2

kai-kzh avatar Aug 28 '17 17:08 kai-kzh

Could you provide a script that makes this issue reproducible? Otherwise I am afraid there is no way to fix it. Thank you.

Byron avatar Sep 28 '17 15:09 Byron

I got that error when trying to create a local branch or head using a remote reference, while the head already existed in my local repo and my local repo was pointing to a past commit. To solve it I just checked if the branch already existed in the repo.heads like

def _create_head_master_from_origin(self):
        if not 'master' in self.repo.heads:
            self.logger.debug("Creating local master branch")
            self.repo.create_head('master', self.origin.refs.master)
        self.repo.heads.master.set_tracking_branch(self.origin.refs.master)

If it already existed just switched to that head and updated it with a pull.

eggonzal avatar Jun 12 '18 05:06 eggonzal

To me it looks like a usability issue that might be worth being looked into.

Byron avatar Jul 15 '18 12:07 Byron