bash - git edit authors name in commit range, script -
i create git script replaces author "a" author "b" in specified commit range (abcd..dcba). how can that? here have far:
#!/bin/sh # # git-mycommand # # git filter-branch --commit-filter ' if [ git rev-list --boundary 02e60c8..dc4c65f ]; if [ "$git_author_name" = "a" ];then git_author_name="b"; fi; fi; git commit-tree "$@"' problem git says
rewrite $sha1-number git commit-tree: line 48: [: many arguments is git rev-list --boundary command legal in if statement? if remove if [git rev-list ... ] statement it'll work.
ideal if can add input variables. command like
git mycommand $authorexpression $authorreplace $commita..$commitb edit: thinks question has been asked. please read problem above again , compare wit asked questions. afaik question (test if commits between commit , commit b) has not been asked yet. if i'm wrong, sorry wasting time. have tried answer question!
others have addressed parameter quoting. big remaining problem test:
if [ git-rev-list ... ] the commit filter shell script fragment, tells shell run command:
[ git-rev-list ... ] and test whether exit status of command 0 (true) or not (false). [ command, known test, not have git built-ins.
what seem want tell whether original commit being filtered member of range a..b inclusive. let's first note this, filter-branch documentation:
the filters applied in order listed below. <command> argument evaluated in shell context using eval command (with notable exception of commit filter, technical reasons). prior that,
$git_commitenvironment variable set contain id of commit being rewritten.
thus, write this:
a=$(git rev-parse $3) || exit 1 b=$(git rev-parse $4) || exit 1 git filter-branch --commit-filter " if git merge-base --is-ancestor \$git_commit $b && ! git merge-base --is-ancestor \$git_commit $a^; the first merge-base tests whether $git_commit ancestor of higher rev (is equal $b or comes "before" topologically). second excludes commits come before lower rev ($a), using hat-suffix avoid excluding $a itself.
here's variant of brian campbell's script using technique (well, changed quote expansion technique too).
#! /bin/sh case $# in 4) ;; *) echo "usage: $0 oldauthor newauthor firstrev lastrev" >&2; exit 1;; esac authorexpression=$1 authorreplace=$2 a=$(git rev-parse --verify $3^{commit}) || exit 1 b=$(git rev-parse --verify $4^{commit}) || exit 1 git filter-branch --commit-filter " if git merge-base --is-ancestor \$git_commit $b && ! git merge-base --is-ancestor \$git_commit $a^; if [ \"\$git_author_name\" = '$authorexpression' ]; git_author_name='$authorreplace' fi fi git commit-tree \"\$@\""
Comments
Post a Comment