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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 2021-01-27 at 08:15:19, Daniel Lublin wrote:
> 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.

> 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

Attachment: signature.asc
Description: PGP signature


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux