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

Re: Create a new commit from patches without using any worktree?

From
Johannes Sixt <j.sixt@viscovery.net>
Date
Oct 27, 2010, 09:07 UTC
Message-ID
<4CC7EBEA.9070804@viscovery.net>
In-Reply-To
<AANLkTi=Xi13_0+bC-TVRP3uVDmGWVdM3a708=SSzCR88@mail.gmail.com>
Am 10/27/2010 3:49, schrieb Klas Lindberg:
> Is there any way to record a new commit based on contents in a patch
> without going through a worktree?

This script may be a starter. It takes a commit on the command line instead of a patch, but it processes that commit as a patch ("diff-tree -p"), so the script should be easy to adapt.

-- Hannes

-- 8< -- #!/bin/sh

OPTIONS_SPEC="\ git post to-ref [from-rev] -- " . git-sh-setup

while test $# != 0
do
	case "$1" in
	--)	shift; break;;
	-*)	usage;;
	*)	break;;
	esac
	shift
done
FROM=$(git rev-parse --verify --symbolic-full-name "$1") || exit
shift
if test $# = 0; then
	set -- HEAD
fi
test $# = 1 || usage

# populate a temporary index tmpidx=$GIT_DIR/index-post-$$ git read-tree --index-output="$tmpidx" "$FROM" || exit GIT_INDEX_FILE=$tmpidx export GIT_INDEX_FILE trap 'rm -f "$tmpidx"' 0 1 2 15

git diff-tree -p -M -C "$@" | git apply --cached || exit
newtree=$(git write-tree) &&
newrev=$(
	eval "$(get_author_ident_from_commit "$1")"
	git-cat-file commit "$1" | sed -e '1,/^$/d' |
	git commit-tree $newtree -p "$FROM"
) || exit
if git check-ref-format "$FROM"
then
	set_reflog_action post
	subject=$(git log --no-walk --pretty=%s "$newrev") &&
	git update-ref -m "$GIT_REFLOG_ACTION: $subject" "$FROM" $newrev || exit
fi
if test -z "$GIT_QUIET"
then
	git rev-list -1 --oneline $newrev
fi
Previous: Jonathan NiederNext: Bert Wesarg
Message 3 of 5 in “Create a new commit from patches without using any worktree?”
  1. Klas LindbergOct 27, 2010
  2. Jonathan NiederOct 27, 2010
  3. Johannes SixtOct 27, 2010
  4. Bert WesargOct 27, 2010
  5. Klas LindbergOct 27, 2010

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.