You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
:class:`Heads <git.refs.head.Head>` Heads are branches in git-speak. :class:`References <git.refs.reference.Reference>` are pointers to a specific commit or to other references. Heads and :class:`Tags <git.refs.tag.TagReference>` are a kind of references. GitPython allows you to query them rather intuitively.
80
80
81
+
To obtain the current commit ID, use ``repo.head.commit.hexsha``. This works both
82
+
on a branch and with a detached HEAD, provided HEAD resolves to an existing commit.
83
+
When ``repo.head.is_detached`` is true, HEAD points directly to a commit and there
84
+
is no active branch: reading ``repo.head.reference`` or ``repo.active_branch``
85
+
raises :exc:`TypeError`. The branch examples below assume an attached HEAD.
86
+
81
87
.. literalinclude:: ../../test/test_docs.py
82
88
:language: python
83
89
:dedent: 8
@@ -152,7 +158,7 @@ Examining References
152
158
:start-after: # [2-test_references_and_objects]
153
159
:end-before: # ![2-test_references_and_objects]
154
160
155
-
A :class:`symbolic reference <git.refs.symbolic.SymbolicReference>` is a special case of a reference as it points to another reference instead of a commit.
161
+
A :class:`symbolic reference <git.refs.symbolic.SymbolicReference>` can point to another reference. When detached, it points directly to a commit instead. Reading its ``commit`` property resolves the commit in either state. Assigning a commit to ``reference`` detaches it; reading ``reference`` then raises :exc:`TypeError`.
0 commit comments