1

Is there a way under the GitPython library to revert local changes to a single file?

Under the Git command line I would just use git checkout filename but attempting to do this under the GitPython API, like so

repo.index.checkout([filename])

leads to the following error,

git.exc.CheckoutError: Some files could not be checked out from the index due to local modifications:['foo']

asked Nov 23, 2011 at 20:58

1 Answer 1

1

Ah, figured it out a few minutes after posting by looking at the source.

If I turn on force by using repo.index.checkout([filename]. force=True) it works fine.

There may be a better way, but according to the source the force parameter is just there to overwrite local changes.

:param force:
If True, existing files will be overwritten even if they contain local modifications.
If False, these will trigger a CheckoutError.

answered Nov 23, 2011 at 21:08
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.