Last active
August 29, 2015 14:13
-
-
Save dkubb/fbb28209884ce70de1cc to your computer and use it in GitHub Desktop.
Git tools
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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 $parent | |
| # Rewrite all commits against the current commit | |
| git filter-branch --force --env-filter "$command" -- "$parent..HEAD" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment