Skip to content

Commit 16a654e

Browse files
committed
📝 Update git section
* Add diff source and destination prefix * Add diff with exiftool * Add git list-changed * Add default branch config for init * Add git-symbolic-ref * Add Git Credential Store for Linux * Update shallow clones * Add shell configs and command line tools * Add aliases for faster resolution of merge conflicts * Add pre-rebase hook for the pre-commit framework * Add git describe * Add anchors
1 parent a3810b2 commit 16a654e

20 files changed

+1126
-316
lines changed

CHANGELOG.rst

+13
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,19 @@ Added
2626
* 📝 Add csv.Sniffer methods
2727
* 📝 Add the removal of git lfs
2828

29+
30+
Changed
31+
~~~~~~~
32+
33+
* 📝 Update git section
34+
35+
* Add diff source and destination prefix
36+
* Add default branch config for init
37+
* Add git-symbolic-ref
38+
* Add Git Credential Store for Linux
39+
* Update shallow clones
40+
* Add shell config and command line tools
41+
2942
`24.3.0 <https://github.com/cusyio/Python4DataScience/compare/24.2.0...24.3.0>`_: 2024-11-03
3043
--------------------------------------------------------------------------------------------
3144

docs/productive/git/advanced/batch.rst

+20-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ Example
2424
changes the permissions for all files with the suffix ``.py`` from
2525
``100644`` to ``100755``, if necessary, so that they become executable.
2626

27+
.. _git-name-only:
28+
2729
All files changed in the working or staging area
2830
------------------------------------------------
2931

@@ -35,9 +37,26 @@ All files changed in the working or staging area
3537
:samp:`git diff --staged --name-only "*.{SUFFIX}"`
3638
also filters for a specific file extension.
3739

40+
.. _list-changed:
41+
42+
:samp:`git diff --name-only --diff-filter d`
43+
excludes deleted files.
44+
45+
This is the most common case for me, which is why I have created a
46+
``list-changed`` alias for this: ``git config --global alias.list-changed
47+
'diff --name-only --diff-filter d'``.
48+
3849
Example
3950
~~~~~~~
4051

41-
:samp:`pytest $(git diff --staged --name-only "tests/test_*.py")`
52+
To execute commands for the changed file list, you can use the shell `Command
53+
Substitution
54+
<https://www.gnu.org/software/bash/manual/html_node/Command-Substitution.html>`_:
55+
56+
:samp:`$ uv run codespell $(git list-changed '*.py')`
57+
The shell executes the ``git list-changed`` in brackets and inserts its
58+
output into the outer command. ``codespell`` therefore receives the list of
59+
changed text files as an argument.
60+
:samp:`uv run pytest $(git diff --staged --name-only "tests/*test_*.py")`
4261
calls :doc:`python-basics:test/pytest/index` to execute only those test
4362
modules that have been changed in the working directory.

docs/productive/git/advanced/binary-files.rst

+88-17
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,16 @@ Then we can use :doc:`pandas:reference/api/pandas.DataFrame.to_csv` in
2424
:language: python
2525

2626
Now add the following section to your global Git configuration
27-
:file:`~/.gitconfig`:
27+
:file:`~/.config/git/config`:
2828

2929
.. code-block:: ini
3030
3131
[diff "excel"]
3232
textconv=python3 /PATH/TO/exceltocsv.py
3333
binary=true
3434
35-
Finally, in the global :file:`~/.gitattributes` file, our ``excel`` converter is
36-
linked to :file:`*.xlsx` files:
35+
Finally, in the global :file:`~/.config/git/attributes` file, our ``excel``
36+
converter is linked to :file:`*.xlsx` files:
3737

3838
.. code-block:: ini
3939
@@ -56,15 +56,16 @@ For this, ``pdftohtml`` is additionally required. It can be installed with
5656
5757
$ brew install pdftohtml
5858
59-
Add the following section to the global Git configuration :file:`~/.gitconfig`:
59+
Add the following section to the global Git configuration
60+
:file:`~/.config/git/config`:
6061

6162
.. code-block:: ini
6263
6364
[diff "pdf"]
6465
textconv=pdftohtml -stdout
6566
66-
Finally, in the global :file:`~/.gitattributes` file, our ``pdf`` converter is
67-
linked to :file:`*.pdf` files:
67+
Finally, in the global :file:`~/.config/git/attributes` file, our ``pdf``
68+
converter is linked to :file:`*.pdf` files:
6869

6970
.. code-block:: ini
7071
@@ -73,10 +74,12 @@ linked to :file:`*.pdf` files:
7374
Now, when ``git diff`` is called, the PDF files are first converted and then a
7475
diff is performed over the outputs of the converter.
7576

76-
… for Word documents
77-
--------------------
77+
.. _pandoc-to-markdown:
7878

79-
Differences in Word documents can also be displayed. For this purpose `Pandoc
79+
… for documents
80+
---------------
81+
82+
Differences in documents can also be displayed. For this purpose `Pandoc
8083
<https://pandoc.org/>`_ can be used, which can be easily installed with
8184

8285
.. tab:: Debian/Ubuntu
@@ -97,24 +100,92 @@ Differences in Word documents can also be displayed. For this purpose `Pandoc
97100
<https://github.com/jgm/pandoc/releases/>`_.
98101

99102
Then add the following section to your global Git configuration
100-
:file:`~/.gitconfig`:
103+
:file:`~/.config/git/attributes`:
101104

102105
.. code-block:: ini
103106
104-
[diff "word"]
105-
textconv=pandoc --to=markdown
106-
binary=true
107-
prompt=false
107+
[diff "pandoc-to-markdown"]
108+
textconv = pandoc --to markdown
109+
cachetextconv = true
108110
109-
Finally, in the global :file:`~/.gitattributes` file, our ``word`` converter is
110-
linked to :file:`*.docx` files:
111+
Finally, in the global :file:`~/.config/git/attributes` file, our
112+
``pandoc-to-markdown`` converter is linked to :file:`*.docx`, :file:`*.odt` and
113+
:file:`*.rtf` files:
111114

112115
.. code-block:: ini
113116
114-
*.docx diff=word
117+
*.docx diff=pandoc-to-markdown
118+
*.odt diff=pandoc-to-markdown
119+
*.rtf diff=pandoc-to-markdown
120+
121+
.. tip::
122+
:doc:`Jupyter Notebooks <jupyter-tutorial:notebook/index>` write to a JSON
123+
file :ref:`*.ipynb <jupyter-tutorial:whats-an-ipynb-file>`, which is quite
124+
dense and difficult to read, especially with diffs. The Markdown
125+
representation of Pandoc simplifies this:
126+
127+
.. code-block:: ini
128+
129+
*.ipynb diff=pandoc-to-markdown
115130
116131
The same procedure can be used to obtain useful diffs from other binaries, for
117132
example ``*.zip``, ``*.jar`` and other archives with ``unzip`` or for changes in
118133
the meta information of images with ``exiv2``. There are also conversion tools
119134
for converting ``*.odt``, ``*.doc`` and other document formats into plain text.
120135
For binary files for which there is no converter, strings are often sufficient.
136+
137+
.. _exiftool:
138+
139+
… for media files
140+
-----------------
141+
142+
`ExifTool <https://exiftool.org>`_ can be used to convert the metadata of media
143+
files to text.
144+
145+
.. tab:: Debian/Ubuntu
146+
147+
.. code-block:: console
148+
149+
$ sudo apt install libimage-exiftool-perl
150+
151+
.. tab:: macOS
152+
153+
.. code-block:: console
154+
155+
$ brew install exiftool
156+
157+
.. tab:: Windows
158+
159+
.. code-block:: ps1
160+
161+
> choco install exiftool
162+
163+
.. seealso::
164+
* `Installing ExifTool <https://exiftool.org/install.html>`_
165+
166+
You can then add the following section to the global Git configuration file
167+
:file:`~/.config/git/config`:
168+
169+
.. code-block:: ini
170+
171+
[diff "exiftool"]
172+
textconv = exiftool --composite -x 'Exiftool:*'
173+
cachetextconv = true
174+
xfuncname = "^-.*$"
175+
176+
Finally, in :file:`~/.config/git/attributes` the ``exiftool`` converter is
177+
linked to file endings of media files:
178+
179+
.. code-block:: ini
180+
181+
*.avif diff=exiftool
182+
*.bmp diff=exiftool
183+
*.gif diff=exiftool
184+
*.jpeg diff=exiftool
185+
*.jpg diff=exiftool
186+
*.png diff=exiftool
187+
*.webp diff=exiftool
188+
189+
.. seealso::
190+
``exiftool`` can process many more media files. You can find a complete list
191+
in `Supported File Types <https://exiftool.org/#supported>`_.
Loading
266 KB
Loading

0 commit comments

Comments
 (0)