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

Re: Automatically exclude hunks from the commit

From
Michael J Gruber <git@drmicha.warpmail.net>
Date
Jul 20, 2010, 09:26 UTC
Message-ID
<4C456BBC.8010203@drmicha.warpmail.net>
In-Reply-To
<4C4511C8.8090405@workspacewhiz.com>
Joshua Jensen venit, vidit, dixit 20.07.2010 05:02:
Show 14 quoted lines
>   I have some files I update frequently where I have some normally 
> commented out debug code purposely uncommented during development.  
> Git's hunk-level staging saves the day.  I can stage everything but the 
> debug code without issue.
> 
> This got me to thinking.  Is there a better way?  Is there a facility in 
> Git where I could mark a hunk as 'permanently frozen unstaged'?  
> Anything marked as such would never be staged for commit.  I could rest 
> assured I would never accidentally commit my debug code, be it extra 
> printfs or a development server or a password or so on.
> 
> Thanks for the help.
> 
> Josh

If you don't want to deal with the branch approach suggested by the other Joshua you could (ab)use the clean&smudge filters (see "filter" in gitattributes(5)):

Define a clean filter such as "fgrep -v GITIGNORE" and mark every source line which you want to ignore with a comment:

printf("Happy we got this far but I have no clue why"); // GITIGNORE

You can do more clever things with awk or sed, of course. "GITIGNORE" is just some hopefully unused string.

Note that a "checkout" would overwrite your debug lines!

Cheers, Michael

Previous: Wincent Colaiuta
Message 4 of 4 in “Automatically exclude hunks from the commit”
  1. Joshua JensenJul 20, 2010
  2. Joshua JuranJul 20, 2010
  3. Wincent ColaiutaJul 20, 2010
  4. Michael J GruberJul 20, 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.