Michael J Gruber <git@xxxxxxxxxxxxxxxxxxxx> writes: > While replace refs are much more general than grafts, it seems the two > main uses are: > > - grafts (change the recorded parents for a commit) > - svn cleanup (convert tagging commits into tag objects) > > The latter one being quite a special case already. > > The script below has helped me move from grafts to replace objects. > While not being super clean, something like it may be fit for contrib. > > I think we ought to help John Doe get along with parents, while we can > safely leave most more advanced operations to people who know how to > edit a raw object file. Putting that facility into "git-commit" seems to > be too encouraging, though - people would use replace when they should > use amend or rebase-i. I'd prefer a special git-replace mode (be it > "--graft" or "--graft-commit") which does just what my script does. We > could add things like "--commit-tag" later, a full blown > "object-factory" seems like overkill. > > Michael > > --->%--- > > #!/bin/sh > > die () { > echo "$@" > rm -f "$commitfile" > exit 1 > } > > warn () { > echo "$@" > } > > test $# -gt 0 || die "Usage: $0 <commit> [<parent>]*" > > for commit > do > git rev-parse --verify -q "$commit" >/dev/null || die "Cannot parse > $commit." > test x$(git cat-file -t $commit) == "xcommit" || die "$commit is no > commit." s/==/=/ or you have to say #!/bin/bash on the first line, I think. Appears multiple times throughout this script. > done > > commit="$1" > shift > > commitfile=$(mktemp) > > git cat-file commit "$commit" | while read a b > do > if test "$a" != "parent" > then > echo $a $b You are losing information on non-header lines by reading without "-r" in the above, and also multi-line headers (e.g. mergetag), aren't you? > fi > if test "$a" == "tree" > then > for parent > do > echo "parent $(git rev-parse $parent)" > done > fi > done >$commitfile > hash=$(git hash-object -t commit -w "$commitfile") || die "Cannot create > commit object." > git replace "$commit" $hash > rm -f $commitfile -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html