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

Re: committing empty diffs

From
Shawn O. Pearce <spearce@spearce.org>
Date
Feb 12, 2007, 20:10 UTC
Message-ID
<20070212201057.GC30440@spearce.org>
In-Reply-To
<20070212200324.GB30440@spearce.org>
"Shawn O. Pearce" <spearce@spearce.org> wrote:
Show 7 quoted lines
> Don Zickus <dzickus@gmail.com> wrote:
> > Considering git-commit doesn't allow this (probably for good reason),
> > is it technically safe to do the following sequence of events?
> > 
> > tree=$(git-write-tree)  #basically the same tree HEAD points to
> > commit=$(echo $IDEAS | git-commit-tree $tree -p HEAD)
> > git-update-ref HEAD $commit HEAD
This can also be written shorter, and safer:
	head=$(git-rev-parse --verify HEAD^0)
	commit=$(echo $IDEAS | git-commit-tree $head^{tree} -p $head)
	git-update-ref HEAD $commit $head

The reason you do it like this is it prevents a HEAD which was modified between the time you did git-commit-tree and git-update-ref from being lost.

And the write-tree is completely unnecessary, and might actually write out a dirty-index, which would make your ideas commit actually modifying files - not what you wanted.

-- 
Shawn.
Previous: Shawn O. PearceNext: Don Zickus
Message 3 of 5 in “committing empty diffs”
  1. Don ZickusFeb 12, 2007
  2. Shawn O. PearceFeb 12, 2007
  3. Shawn O. PearceFeb 12, 2007
  4. Don ZickusFeb 12, 2007
  5. Linus TorvaldsFeb 12, 2007

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.