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

Re: Bug Report: Creating a hardlink to any of the file in git repo cause the source file to show up in git commit message editor under "Changes not staged for commit" section.

From
Junio C Hamano <gitster@pobox.com>
Date
Jul 18, 2011, 18:37 UTC
Message-ID
<7vwrffjuym.fsf@alter.siamese.dyndns.org>
In-Reply-To
<02a20a168c52beb42e57258bcc5c0551@mail.mxes.net>
Michael <git-scm@webhippo.net> writes:
> echo "ln -vf FILE2 ../HARDLINK_TO_FILE2" >| .git/hooks/pre-commit
> echo "rm -vf ../HARDLINK_TO_FILE2" >> .git/hooks/pre-commit
> echo "ln -vf FILE3 ../HARDLINK_TO_FILE3" >> .git/hooks/pre-commit
> echo "rm -vf ../HARDLINK_TO_FILE3" >> .git/hooks/pre-commit

This does not have to do anything with hardlink. A simple "touch" should do as long as FILE2/FILE3 are sufficiently old.

You are smudging cached stat information in your pre-commit hook (st_ctime would be different), and that is shown as a difference between the working tree and the index (note that nowhere in githooks documentation we say pre-commit hook is allowed to muck with the working tree files). I think we do refresh the cached stat information before running the pre-commit hook so that the hook can check the list of working tree files that are different from the index using diff-files, but the purpose of the said hook is to validate, and not affect, the state of the working tree, and I wouldn't be surprised if we do not update the cached stat information after the hook returns control to us.

If you really want to munge the working tree inside pre-commit, I think adding "git update-index --refresh" at the end of pre-commit hook would make the phantom change go away.

Previous: Michael
Message 2 of 2 in “Bug Report: Creating a hardlink to any of the file in git repo cause the source file to show up in git commit message editor under "Changes not staged for commit" section.”
  1. MichaelJul 18, 2011
  2. Junio C HamanoJul 18, 2011

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.