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

Re: Disallow amending published commits?

From
Jeff King <peff@peff.net>
Date
Mar 22, 2009, 02:42 UTC
Message-ID
<20090322024226.GA6766@coredump.intra.peff.net>
In-Reply-To
<885649360903211056u38ff6cabxbe1a17d57faaa0c4@mail.gmail.com>
On Sat, Mar 21, 2009 at 10:56:26AM -0700, James Pickens wrote:
Show 5 quoted lines
> I wanted to have a pre-commit hook that would prevent users from
> amending a commit that had already been published, but I couldn't
> find any way in the pre-commit hook to figure out if --amend was
> used.  Is there a way to do that?  Or any better way to disallow
> amending published commits?

I don't think so; as somebody already mentioned, the usual time to resolve such issues is at push-time. However, I can see how it would be convenient to catch such a problem early, since by the time you push, it may be much later and you don't remember exactly why you amended instead of building on top (or as you indicated, your workflow may involve pulling).

I suspect the right way to go about this is to inform the pre-commit hook about the parents of the proposed commit. It already knows the current branch (since it is in HEAD), and from there you should be able to implement any policy logic regarding changing the shape of history (including your request).

Right now that information is totally contained within the git-commit process; probably the simplest thing would be to export a space-separated list of SHA-1's to the hook.

-Peff
Previous: Nicolas Sebrecht
Message 9 of 9 in “Disallow amending published commits?”
  1. James PickensMar 21, 2009
  2. Peter HarrisMar 21, 2009
  3. James PickensMar 21, 2009
  4. Peter HarrisMar 22, 2009
  5. Peter HarrisMar 22, 2009
  6. James PickensMar 22, 2009
  7. Peter HarrisMar 22, 2009
  8. Nicolas SebrechtMar 22, 2009
  9. Jeff KingMar 22, 2009

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.