Skip to content

Instantly share code, notes, and snippets.

@dkubb
Last active August 29, 2015 14:13
Show Gist options
  • Select an option

  • Save dkubb/fbb28209884ce70de1cc to your computer and use it in GitHub Desktop.

Select an option

Save dkubb/fbb28209884ce70de1cc to your computer and use it in GitHub Desktop.

Revisions

  1. dkubb renamed this gist Feb 13, 2015. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. dkubb revised this gist Feb 13, 2015. 4 changed files with 1 addition and 61 deletions.
    1 change: 1 addition & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    Moved to https://github.com/dkubb/git-tools
    21 changes: 0 additions & 21 deletions git-fix-branch
    Original file line number Diff line number Diff line change
    @@ -1,21 +0,0 @@
    #!/usr/bin/env bash

    # Fix branch commit data to be the same as author data

    set -euo pipefail
    IFS=$'\n\t'

    parent=${1-master}

    # The command to execute for each commit
    read -r -d '' command <<-'COMMAND' || true
    export GIT_COMMITTER_NAME="$GIT_AUTHOR_NAME"
    export GIT_COMMITTER_EMAIL="$GIT_AUTHOR_EMAIL"
    export GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE"
    COMMAND

    # Rebase the current branch on top of the parent
    git rebase --keep-empty -- $parent

    # Rewrite all commits against the current commit
    git filter-branch --force --env-filter "$command" -- "$parent..HEAD"
    16 changes: 0 additions & 16 deletions git-prune-all
    Original file line number Diff line number Diff line change
    @@ -1,16 +0,0 @@
    #!/usr/bin/env bash

    # Prune all merged local and remote branches

    set -euo pipefail
    IFS=$'\n\t'

    branch=$(git rev-parse --abbrev-ref HEAD)
    remote=$(git config "branch.${branch}.remote")

    git remote update > /dev/null
    git remote prune "$remote"

    git branch --remotes --merged "$remote/$branch" \
    | awk -F\"/\" "!/(>|$branch)/ {print \$2}" \
    | xargs --no-run-if-empty --max-lines 1 git push "$remote" --delete
    24 changes: 0 additions & 24 deletions git-push-each
    Original file line number Diff line number Diff line change
    @@ -1,24 +0,0 @@
    #!/usr/bin/env bash

    # Push commits individually to trigger CI builds for each

    set -euo pipefail
    IFS=$'\n\t'

    parent=${1-master}
    branch=$(git rev-parse --abbrev-ref HEAD)
    remote=$(git config "branch.${branch}.remote")

    # Commits in the local branch not in the remote branch
    commits=$(
    comm -13 \
    <(git rev-list "$remote/$parent..$remote/$branch" --reverse) \
    <(git rev-list "$parent..$branch" --reverse)
    )

    # Push all commits not in the parent branch
    for commit in $commits
    do
    # Trigger CI for each commit by pushing them individually
    git push --force "$remote" "$commit:$branch"
    done
  3. dkubb revised this gist Feb 13, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion git-fix-branch
    Original file line number Diff line number Diff line change
    @@ -15,7 +15,7 @@ export GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE"
    COMMAND

    # Rebase the current branch on top of the parent
    git rebase $parent
    git rebase --keep-empty -- $parent

    # Rewrite all commits against the current commit
    git filter-branch --force --env-filter "$command" -- "$parent..HEAD"
  4. dkubb renamed this gist Feb 10, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion git-reb → git-fix-branch
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    #!/usr/bin/env bash

    # Rebase a branch on a parent branch, preserving commit metadata
    # Fix branch commit data to be the same as author data

    set -euo pipefail
    IFS=$'\n\t'
  5. dkubb created this gist Jan 9, 2015.
    16 changes: 16 additions & 0 deletions git-prune-all
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    #!/usr/bin/env bash

    # Prune all merged local and remote branches

    set -euo pipefail
    IFS=$'\n\t'

    branch=$(git rev-parse --abbrev-ref HEAD)
    remote=$(git config "branch.${branch}.remote")

    git remote update > /dev/null
    git remote prune "$remote"

    git branch --remotes --merged "$remote/$branch" \
    | awk -F\"/\" "!/(>|$branch)/ {print \$2}" \
    | xargs --no-run-if-empty --max-lines 1 git push "$remote" --delete
    24 changes: 24 additions & 0 deletions git-push-each
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    #!/usr/bin/env bash

    # Push commits individually to trigger CI builds for each

    set -euo pipefail
    IFS=$'\n\t'

    parent=${1-master}
    branch=$(git rev-parse --abbrev-ref HEAD)
    remote=$(git config "branch.${branch}.remote")

    # Commits in the local branch not in the remote branch
    commits=$(
    comm -13 \
    <(git rev-list "$remote/$parent..$remote/$branch" --reverse) \
    <(git rev-list "$parent..$branch" --reverse)
    )

    # Push all commits not in the parent branch
    for commit in $commits
    do
    # Trigger CI for each commit by pushing them individually
    git push --force "$remote" "$commit:$branch"
    done
    21 changes: 21 additions & 0 deletions git-reb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    #!/usr/bin/env bash

    # Rebase a branch on a parent branch, preserving commit metadata

    set -euo pipefail
    IFS=$'\n\t'

    parent=${1-master}

    # The command to execute for each commit
    read -r -d '' command <<-'COMMAND' || true
    export GIT_COMMITTER_NAME="$GIT_AUTHOR_NAME"
    export GIT_COMMITTER_EMAIL="$GIT_AUTHOR_EMAIL"
    export GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE"
    COMMAND

    # Rebase the current branch on top of the parent
    git rebase $parent

    # Rewrite all commits against the current commit
    git filter-branch --force --env-filter "$command" -- "$parent..HEAD"