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

Re: "discard!" commit message for commits that should be removed while cleaning up the history

From
Junio C Hamano <gitster@pobox.com>
Date
Jul 12, 2026, 13:28 UTC
Message-ID
<xmqqbjcc72wo.fsf@gitster.g>
In-Reply-To
<07c9811e-41db-473e-ba0a-cdcbf8187be7@hogyros.de>
Simon Richter <Simon.Richter@hogyros.de> writes:
Show 7 quoted lines
> I often add printf statements during debugging, which obviously should 
> not end up in the final submission. My usual approach is to commit these 
> immediately, into commits with a message of "DISCARD", so that when I do 
> a final rebase pass, I can remove the debug code easily.
>
> Would it make sense to add a mechanism that autosquash understands 
> directly, and that could be checked for by a push hook or CI rule?

The sequencer machinery used by "git rebase [-i]" already knows how to react to commits with certain subjects. For example, a commit with the subject "fixup! <title>" causes that commit to be moved next to the target commit, and its "pick" insn is turned into a "fixup" insn. The "git commit" command itself helps you prepare such a specially formatted commit title with options like "--fixup".

So, it is not totally out of the question to add support for noticing a subject that begins with "drop!" (rather than your proposed "DISCARD", purely so that it matches the existing "fixup!" convention that instructs the sequencer to use the "fixup" insn). This would automatically turn the "pick" insn into a "drop" insn when "git rebase -i" works on a history segment that includes such a commit.

On the "git commit" side, we likely do not want to add any support similar to the "--fixup" option (for example, "--fixup=drop"), as you can run "git commit -m 'drop!'" just as easily.

Having said all that, you can use a custom GIT_SEQUENCE_EDITOR that notices commits you titled "DISCARD" and rewrites the "pick" insn for these commits into a "drop" insn in the todo list, without making any changes to Git.

Previous: Simon Richter
Message 2 of 2 in “"discard!" commit message for commits that should be removed while cleaning up the history”
  1. Simon RichterJul 12, 2026
  2. Junio C HamanoJul 12, 2026

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.