File: git-add-reset.rst

package info (click to toggle)
python-pygit2 1.18.1-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 2,720 kB
  • sloc: ansic: 12,584; python: 9,337; sh: 205; makefile: 26
file content (67 lines) | stat: -rw-r--r-- 1,887 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
**********************************************************************
git-add / git-reset
**********************************************************************

----------------------------------------------------------------------
Add file contents to the index / Stage
----------------------------------------------------------------------

We can add a new (untracked) file or a modified file to the index.

.. code-block:: bash

    $ git add foo.txt

.. code-block:: python

    >>> index = repo.index
    >>> index.add(path)
    >>> index.write()

----------------------------------------------------------------------
Restore the entry in the index / Unstage
----------------------------------------------------------------------

.. code-block:: bash

    $ git reset HEAD src/tree.c

.. code-block:: python

    >>> index = repo.index

    # Remove path from the index
    >>> path = 'src/tree.c'
    >>> index.remove(path)

    # Restore object from db
    >>> obj = repo.revparse_single('HEAD').tree[path] # Get object from db
    >>> index.add(pygit2.IndexEntry(path, obj.id, obj.filemode)) # Add to index

    # Write index
    >>> index.write()

----------------------------------------------------------------------
Query the index state / Is file staged ?
----------------------------------------------------------------------

.. code-block:: bash

    $ git status foo.txt

.. code-block:: python

    # Return True is the file is modified in the working tree
    >>> repo.status_file(path) & pygit2.enums.FileStatus.WT_MODIFIED

----------------------------------------------------------------------
References
----------------------------------------------------------------------

- git-add_.

.. _git-add: https://www.kernel.org/pub/software/scm/git/docs/git-add.html

- git-reset_.

.. _git-reset: https://www.kernel.org/pub/software/scm/git/docs/git-reset.html