Last active
October 29, 2017 08:58
-
-
Save carlosmn/0232fcd502495eb0b0e2 to your computer and use it in GitHub Desktop.
An extremely case-specific implementation of git-filter-branch
This file contains 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
#!/bin/bash | |
# It's no libgit2, but it's pretty useful | |
. $(git --exec-path)/git-sh-setup | |
cd_to_toplevel | |
require_clean_work_tree | |
set -e | |
# git-sh-setup provides get_author_ident_from_commit but not this one, so let's just copy it | |
get_committer_ident_from_commit () { | |
encoding=$(git config i18n.commitencoding || echo UTF-8) | |
git show -s --pretty=raw --encoding="$encoding" "$1" -- | | |
parse_ident_from_commit committer COMMITTER | |
} | |
clear_local_git_env | |
# Detach and put us on the first commit which doesn't get rewritten | |
git checkout -q -f 41bc8c6 | |
# Now we need to put the other two on top, we take their tree and | |
# commit that, keeping their commiter ident intact as well | |
pick_one () { | |
local active_commit="$1" | |
clear_local_git_env | |
eval $(get_author_ident_from_commit "$active_commit") | |
eval $(get_committer_ident_from_commit "$active_commit") | |
export GIT_COMMITTER_NAME GIT_COMMITTER_EMAIL GIT_COMMITTER_DATE | |
git read-tree "$active_commit" | |
git commit -q -C "$active_commit" | |
clear_local_git_env | |
} | |
pick_one 6dcf9bf75 | |
pick_one e90810b8d | |
git checkout -q -f | |
git checkout -q -B test | |
echo "There you go, boss, your rewritten test branch is at" | |
git rev-parse HEAD |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment