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

Re: git stash push --patch offers skip-worktree hunks

From
brian m. carlson <sandals@crustytoothpaste.net>
Date
Jan 27, 2021, 13:21 UTC
Message-ID
<YBFo8xJu57fC1PO/@camp.crustytoothpaste.net>
In-Reply-To
<rur7en$16bk$1@ciao.gmane.io>
On 2021-01-27 at 08:15:19, Daniel Lublin wrote:
Show 5 quoted lines
> Hi,
> 
> I'm using this to hide some locally modified files from accidental commit:
> 
>   git update-index --skip-worktree ...

This isn't the intended purpose of this functionality, and as you've seen it doesn't work properly for that case. From gitfaq(7):

How do I ignore changes to a tracked file?
  Git doesn't provide a way to do this.  The reason is that if Git needs
  to overwrite this file, such as during a checkout, it doesn't know
  whether the changes to the file are precious and should be kept, or
  whether they are irrelevant and can safely be destroyed.  Therefore,
  it has to take the safe route and always preserve them.
  It's tempting to try to use certain features of `git update-index`,
  namely the assume-unchanged and skip-worktree bits, but these don't
  work properly for this purpose and shouldn't be used this way.
  If your goal is to modify a configuration file, it can often be
  helpful to have a file checked into the repository which is a template
  or set of defaults which can then be copied alongside and modified as
  appropriate.  This second, modified file is usually ignored to prevent
  accidentally committing it.

There is a lot of misinformation on Stack Overflow, which is why I wrote that FAQ entry. Unfortunately, I can only downvote a wrong answer once.

The skip-worktree bit is designed to prevent the file from being checked out as part of sparse checkout.

Show 9 quoted lines
> Doing `git stash push` does not result in the above modifications being
> stashed. But, doing `git stash push --patch` asks me about hunks in the
> files which were flagged to skip-worktree. Instinctively, this feels wrong.
> The docs also say:
> 
>   Interactively select hunks from the diff between HEAD and the working tree
>   to be stashed.
> 
> What do you think?

It looks like there is a test for the case without --push in t3903, and it looks like Dscho (CC'd) last touched it, so maybe he's familiar with what might be going on here.

-- 
brian m. carlson (he/him or they/them)
Houston, Texas, US
Previous: Daniel Lublin
Message 2 of 2 in “git stash push --patch offers skip-worktree hunks”
  1. Daniel LublinJan 27, 2021
  2. brian m. carlsonJan 27, 2021

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.