Table of contents

git

%3 cluster_4b44d0da_0a69_47e6_a9a0_d1ac4779c42f git cluster_16f51c9e_a0aa_43b5_a61d_a75ab5c82c96 Rebase a sub-branch out of a parent and onto a grandparent _6abc3c14_c875_437b_b8b7_84f4418e388b Don't commit when adding lines that contain NOCOMMIT _907efcaa_cf58_4edc_85ff_c7f9bb4224c0 Tutorials _24add57d_042a_46eb_b8c2_d1f7a7c1c001 Get `git diff`s over Word files _5c50f50b_c6cd_4808_8519_e095ee976da8 On git docs _93b4589d_e34a_4ef1_984b_8cf55966ee2d Find common parent between two branches _25b60141_585f_4882_89de_165b719a87c1 Fix the author string in multiple commits _98da3310_108d_4026_a1d2_23e3e896ee9c Ignore formatting commits in git-blame _ccebcc6f_d615_49e1_a06a_0e735b8bb029 SourceHut _ccebcc6f_d615_49e1_a06a_0e735b8bb029->__0:cluster_4b44d0da_0a69_47e6_a9a0_d1ac4779c42f _2e7de173_19a3_4cdc_a2dd_8feedd85f770 Get `git diff`s over ODT files _2e7de173_19a3_4cdc_a2dd_8feedd85f770->__1:cluster_4b44d0da_0a69_47e6_a9a0_d1ac4779c42f _d740b1f8_bb1a_4a3a_b482_600f10a88f8c sqlite in git _d740b1f8_bb1a_4a3a_b482_600f10a88f8c->__2:cluster_4b44d0da_0a69_47e6_a9a0_d1ac4779c42f _c33fa72c_7f9b_4c3d_86a4_25f5fcb46b4f email + git = <3 _85bc6a6c_f6f3_4582_a37c_ec29735f9f8f Reviewing git contributions via email _c33fa72c_7f9b_4c3d_86a4_25f5fcb46b4f->_85bc6a6c_f6f3_4582_a37c_ec29735f9f8f _c33fa72c_7f9b_4c3d_86a4_25f5fcb46b4f->__3:cluster_4b44d0da_0a69_47e6_a9a0_d1ac4779c42f _f7ff2d1a_0fb8_4bcb_9bbe_3b2757515689 GIT PURR! Git Commands Explained with Cats! _f7ff2d1a_0fb8_4bcb_9bbe_3b2757515689->__4:cluster_4b44d0da_0a69_47e6_a9a0_d1ac4779c42f _eb2b712a_f27a_494b_9037_ca2c1fae598b Cómo trabajar con SQLite3 desde Emacs _eb2b712a_f27a_494b_9037_ca2c1fae598b->__5:cluster_4b44d0da_0a69_47e6_a9a0_d1ac4779c42f _345d6325_2ac8_4012_8f03_676abf0f02e2 In a git repository, where do your files live? _1288f07b_1890_45a2_bd67_6684650441ba What is in that .git directory? _345d6325_2ac8_4012_8f03_676abf0f02e2->_1288f07b_1890_45a2_bd67_6684650441ba _345d6325_2ac8_4012_8f03_676abf0f02e2->__6:cluster_4b44d0da_0a69_47e6_a9a0_d1ac4779c42f _85bc6a6c_f6f3_4582_a37c_ec29735f9f8f->_c33fa72c_7f9b_4c3d_86a4_25f5fcb46b4f _85bc6a6c_f6f3_4582_a37c_ec29735f9f8f->__7:cluster_4b44d0da_0a69_47e6_a9a0_d1ac4779c42f _1288f07b_1890_45a2_bd67_6684650441ba->_345d6325_2ac8_4012_8f03_676abf0f02e2 _1288f07b_1890_45a2_bd67_6684650441ba->__8:cluster_4b44d0da_0a69_47e6_a9a0_d1ac4779c42f

Don't commit when adding lines that contain NOCOMMIT

The following prevents the commit from completing, and returns code 1. Put this on the repository's .git/hooks/pre-commit (or add it if it already exists), then make it executable chmod +x .git/hooks/pre-commit

#!/usr/bin/env bash

git diff --cached |grep 'NOCOMMIT' >>/dev/null
if [ $? -eq 0 ];then
    echo -e 'Content marked as \x1b[1;31mNOCOMMIT\x1b[0m'
    exit 1
fi

Result:

Ignore formatting commits in git-blame

A long-standing argument against moving to automated code formatters like Black is that the migration will clutter up the output of git blame. [...]

So when migrating your project's code style to Black, reformat everything and commit the changes (preferably in one massive commit). Then put the full 40 characters commit identifier(s) into a file.

```ini
# Migrate code style to Black
5b4ab991dede475d393e9d69ec388fd6bd949699
```

Afterwards, you can pass that file to git blame and see clean and meaningful blame information.

```bash
$ git blame important.py --ignore-revs-file .git-blame-ignore-revs
7a1ae265 (John Smith 2019-04-15 15:55:13 -0400 1) def very_important_function(text, file):
abdfd8b0 (Alice Doe  2019-09-23 11:39:32 -0400 2)     text = text.lstrip()
7a1ae265 (John Smith 2019-04-15 15:55:13 -0400 3)     with open(file, "r+") as f:
7a1ae265 (John Smith 2019-04-15 15:55:13 -0400 4)         f.write(formatted)
```

You can even configure git to automatically ignore revisions listed in a file on every call to git blame.

```bash
$ git config blame.ignoreRevsFile .git-blame-ignore-revs
The one caveat is that GitHub and GitLab do not yet support ignoring revisions using their native UI of blame.
```

Rebase a sub-branch out of a parent and onto a grandparent

snippet

Suppose we have this cascade of branches.

  • develop

    • dev/feature-branch

      • dev/quick-fix

develop -- <...commits...> -- dev/feature-branch -- <...commits...> -- dev/quick-fix

And we want to move dev/quick-fix out of dev/feature-branch

  • develop

    • dev/feature-branch

    • dev/quick-fix

develop -- <...commits...> -- dev/feature-branch
        \- <...commits...> -- dev/quick-fix

To do this run

git rebase --onto develop dev/feature-branch dev/quick-fix

On git docs

docs

Another example of --onto option is to rebase part of a branch. If we have the following situation:

H---I---J topicB
                       /
              E---F---G  topicA
             /
A---B---C---D  master

then the command

git rebase --onto master topicA topicB

would result in:

H'--I'--J'  topicB
            /
            | E---F---G  topicA
            |/
A---B---C---D  master

This is useful when topicB does not depend on topicA.

Find common parent between two branches

snippet

git merge-base HEAD develop