Skip to content

Instantly share code, notes, and snippets.

@RedFlames
Last active October 9, 2022 02:00
Show Gist options
  • Save RedFlames/ce4eab93bc98df21e6d8cff7e7dd5c23 to your computer and use it in GitHub Desktop.
Save RedFlames/ce4eab93bc98df21e6d8cff7e7dd5c23 to your computer and use it in GitHub Desktop.

Revisions

  1. RedFlames revised this gist Oct 9, 2022. 1 changed file with 5 additions and 0 deletions.
    5 changes: 5 additions & 0 deletions git.md
    Original file line number Diff line number Diff line change
    @@ -2,6 +2,11 @@ Enough cheat sheets out there, https://jdsalaro.com/blog/git-cheat-sheet.html lo

    This is just other voodoo I've used before

    ```sh
    # Number of commits ahead / behind
    git rev-list --left-right --count main...mybranch
    ```

    ```sh
    # list branches with dates, latest committed at the bottom
    git for-each-ref --sort=committerdate refs/heads/ --format='%(committerdate:short) %(refname:short)'
  2. RedFlames revised this gist Oct 9, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion git.md
    Original file line number Diff line number Diff line change
    @@ -37,7 +37,7 @@ git log --all --source -- CelesteNet.Client/Components/CelesteNetMainComponent.c
    ```sh
    # yoink specific PRs commits
    for pull in 22 23 24 25 27; do
    curl -s -H "Accept: application/vnd.github+json" -H "Authorization: token $PAT" "https://api.github.com/repos/0x0ade/CelesteNet/pulls/$pull/commits > pr_$pull.txt
    curl -s -H "Accept: application/vnd.github+json" -H "Authorization: token $PAT" "https://api.github.com/repos/0x0ade/CelesteNet/pulls/$pull/commits" > pr_$pull.txt
    done

    # dump out just the commit hashes from the jsons
  3. RedFlames revised this gist Oct 9, 2022. 1 changed file with 6 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions git.md
    Original file line number Diff line number Diff line change
    @@ -3,11 +3,13 @@ Enough cheat sheets out there, https://jdsalaro.com/blog/git-cheat-sheet.html lo
    This is just other voodoo I've used before

    ```sh
    # list branches with dates, latest committed at the bottom
    git for-each-ref --sort=committerdate refs/heads/ --format='%(committerdate:short) %(refname:short)'

    git for-each-ref --sort=committerdate refs/heads/ --format='%(committerdate:short) %(refname:short)' --merged
    git for-each-ref --sort=committerdate refs/heads/ --format='%(committerdate:short) %(refname:short)' --no-merged

    # both of the above two lines mashed together
    ( OPTS="--sort=committerdate refs/heads/ --format %(committerdate:iso)_%(refname:short)"; git for-each-ref $OPTS --merged=main | sed 's/:[0-9]\{2\} +0[0-9]00_/ -m- /g'; git for-each-ref $OPTS --no-merged=main | sed 's/:[0-9]\{2\} +0[0-9]00_/ - - /g' ) | sort -n
    # aka
    (
    @@ -28,18 +30,22 @@ git rev-list --all | \
    ```

    ```sh
    # list branches that touch a file or idk
    git log --all --source -- CelesteNet.Client/Components/CelesteNetMainComponent.cs | grep -o "refs/heads/.*" | sort -u | xargs -I '{}' git log -1 --format=%aI%x20%S '{}' -- CelesteNet.Client/Components/CelesteNetMainComponent.cs | sort
    ```

    ```sh
    # yoink specific PRs commits
    for pull in 22 23 24 25 27; do
    curl -s -H "Accept: application/vnd.github+json" -H "Authorization: token $PAT" "https://api.github.com/repos/0x0ade/CelesteNet/pulls/$pull/commits > pr_$pull.txt
    done
    # dump out just the commit hashes from the jsons
    for pull in 22 23 24 25 27; do
    commits="$(jq -r '.[]|.sha' < pr_$pull.txt)"
    echo "$commits"
    done | tr -d '\r' > pr_commits.txt
    # list commits since date X that weren't in the PRs
    git log --no-merges --since=2022-01-19 --oneline --no-abbrev-commit | grep -v -f pr_commits.txt
    ```
  4. RedFlames revised this gist Oct 9, 2022. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion git.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,6 @@
    Enough cheat sheets, https://jdsalaro.com/blog/git-cheat-sheet.html looks interesting
    Enough cheat sheets out there, https://jdsalaro.com/blog/git-cheat-sheet.html looks interesting

    This is just other voodoo I've used before

    ```sh
    git for-each-ref --sort=committerdate refs/heads/ --format='%(committerdate:short) %(refname:short)'
  5. RedFlames revised this gist Oct 9, 2022. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions git.md
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    Enough cheat sheets, https://jdsalaro.com/blog/git-cheat-sheet.html looks interesting

    ```
    ```sh
    git for-each-ref --sort=committerdate refs/heads/ --format='%(committerdate:short) %(refname:short)'

    git for-each-ref --sort=committerdate refs/heads/ --format='%(committerdate:short) %(refname:short)' --merged
    @@ -15,7 +15,7 @@ git for-each-ref --sort=committerdate refs/heads/ --format='%(committerdate:shor
    ) | sort -n
    ```

    ```
    ```sh
    # absurd: grep in all commits
    git rev-list --all | \
    (
    @@ -25,11 +25,11 @@ git rev-list --all | \
    )
    ```

    ```
    ```sh
    git log --all --source -- CelesteNet.Client/Components/CelesteNetMainComponent.cs | grep -o "refs/heads/.*" | sort -u | xargs -I '{}' git log -1 --format=%aI%x20%S '{}' -- CelesteNet.Client/Components/CelesteNetMainComponent.cs | sort
    ```

    ```
    ```sh
    for pull in 22 23 24 25 27; do
    curl -s -H "Accept: application/vnd.github+json" -H "Authorization: token $PAT" "https://api.github.com/repos/0x0ade/CelesteNet/pulls/$pull/commits > pr_$pull.txt
    done
  6. RedFlames renamed this gist Oct 9, 2022. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  7. RedFlames created this gist Oct 9, 2022.
    43 changes: 43 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,43 @@
    Enough cheat sheets, https://jdsalaro.com/blog/git-cheat-sheet.html looks interesting

    ```
    git for-each-ref --sort=committerdate refs/heads/ --format='%(committerdate:short) %(refname:short)'

    git for-each-ref --sort=committerdate refs/heads/ --format='%(committerdate:short) %(refname:short)' --merged
    git for-each-ref --sort=committerdate refs/heads/ --format='%(committerdate:short) %(refname:short)' --no-merged

    ( OPTS="--sort=committerdate refs/heads/ --format %(committerdate:iso)_%(refname:short)"; git for-each-ref $OPTS --merged=main | sed 's/:[0-9]\{2\} +0[0-9]00_/ -m- /g'; git for-each-ref $OPTS --no-merged=main | sed 's/:[0-9]\{2\} +0[0-9]00_/ - - /g' ) | sort -n
    # aka
    (
    OPTS="--sort=committerdate refs/heads/ --format %(committerdate:iso)_%(refname:short)"
    git for-each-ref $OPTS --merged=main | sed 's/:[0-9]\{2\} +0[0-9]00_/ -m- /g'
    git for-each-ref $OPTS --no-merged=main | sed 's/:[0-9]\{2\} +0[0-9]00_/ - - /g'
    ) | sort -n
    ```

    ```
    # absurd: grep in all commits
    git rev-list --all | \
    (
    while read revision; do
    git grep -F 'Something' $revision
    done
    )
    ```

    ```
    git log --all --source -- CelesteNet.Client/Components/CelesteNetMainComponent.cs | grep -o "refs/heads/.*" | sort -u | xargs -I '{}' git log -1 --format=%aI%x20%S '{}' -- CelesteNet.Client/Components/CelesteNetMainComponent.cs | sort
    ```

    ```
    for pull in 22 23 24 25 27; do
    curl -s -H "Accept: application/vnd.github+json" -H "Authorization: token $PAT" "https://api.github.com/repos/0x0ade/CelesteNet/pulls/$pull/commits > pr_$pull.txt
    done

    for pull in 22 23 24 25 27; do
    commits="$(jq -r '.[]|.sha' < pr_$pull.txt)"
    echo "$commits"
    done | tr -d '\r' > pr_commits.txt

    git log --no-merges --since=2022-01-19 --oneline --no-abbrev-commit | grep -v -f pr_commits.txt
    ```