From: Michael J Gruber Date: Fri, 21 Dec 2012 12:47:52 GMT Subject: Re: [BUG] Cannot push some grafted branches Message-ID: <50D45A78.3020104@drmicha.warpmail.net> In-Reply-To: <7vvcbx956f.fsf@alter.siamese.dyndns.org> 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 []*" 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." done commit="$1" shift commitfile=$(mktemp) git cat-file commit "$commit" | while read a b do if test "$a" != "parent" then echo $a $b 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