git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [BUG] Cannot push some grafted branches

From
Michael J Gruber <git@drmicha.warpmail.net>
Date
Dec 21, 2012, 12:47 UTC
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 <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."
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
Previous: Junio C HamanoNext: Junio C Hamano
Message 27 of 29 in “[BUG] Cannot push some grafted branches”
  1. Yann DirsonDec 11, 2012
  2. Junio C HamanoDec 11, 2012
  3. Yann DirsonDec 12, 2012
  4. Yann DirsonDec 12, 2012
  5. Junio C HamanoDec 12, 2012
  6. Yann DirsonDec 17, 2012
  7. Junio C HamanoDec 17, 2012
  8. Yann DirsonDec 17, 2012
  9. Thomas RastDec 17, 2012
  10. Yann DirsonDec 17, 2012
  11. Christian CouderDec 17, 2012
  12. Yann DirsonDec 17, 2012
  13. Andreas SchwabDec 17, 2012
  14. Junio C HamanoDec 17, 2012
  15. Yann DirsonDec 18, 2012
  16. Johannes SixtDec 18, 2012
  17. Thomas RastDec 18, 2012
  18. Yann DirsonDec 18, 2012
  19. Thomas RastDec 18, 2012
  20. Jeff KingDec 18, 2012
  21. Johannes SixtDec 19, 2012
  22. Jeff KingDec 19, 2012
  23. Junio C HamanoDec 18, 2012
  24. Yann DirsonDec 19, 2012
  25. Thomas RastDec 19, 2012
  26. Junio C HamanoDec 19, 2012
  27. Michael J GruberDec 21, 2012
  28. Junio C HamanoDec 21, 2012
  29. Michael J GruberDec 22, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.