Per-worktree local exclusion
Asked Answered
T

1

6

I'd like to use local file exclusion on a worktree. I tried adding the file name to .git/worktrees/$worktreename/info/exclude but it doesn't take. The analogous file .git/info/exclude works, but applies to all worktrees, not just the main one.

Tilt answered 14/2, 2018 at 4:8 Comment(0)
C
5

but it doesn't take

I do not see an info/exclude in .git/worktrees official layout documentation.

A workaround would to have a branch-specific .gitignore content.
That means adding your untracked file to the worktree .gitignore remains the best option.
And you can ignore modification on that (tracked) .gitignore file with the update-index command seen here.

git update-index --assume-unchanged -- .gitignore

That allows you for the local exclusion you are after.

Calve answered 14/2, 2018 at 5:46 Comment(10)
I am not using Visual Studio. I was using Git 2.15 when I asked the question, but upgrading now to 2.16 didn't change the behaviour.Tilt
@Tilt Then my comment about git/wortrees layout stands: there does not seem to be any .git/worktrees/info/exclude file managed by Git at the moment.Calve
@Tilt Note that if by "local ignore" you mean ignore modification for an already tracked file, that would be done with a git update-index command: https://mcmap.net/q/297112/-with-git-temporary-exclude-a-changed-tracked-file-from-commit-in-command-line. For an untracked file, adding it to the .gitignore remains the common solution.Calve
no, that's not what I mean -- the behaviour I am after is exactly as if I had multiple independent repos instead of worktrees, each with its own .git/info/exclude file.Tilt
@Tilt So we are talking about untracked file, right?Calve
yes, I am talking about untracked files that I don't want to show up in git status etc.Tilt
Another option would be to set per worktree, the config core.excludesFile in order to reference a different file on each worktree... but I do't think you can have more than one local config (git-scm.com/docs/…)Calve
So, adding your untracked file to the worktree .gitignore remains the best option. And you can ignore modification on that (tracked .gitignore file) with the update-index command I mentioned before in https://mcmap.net/q/297112/-with-git-temporary-exclude-a-changed-tracked-file-from-commit-in-command-lineCalve
can you edit your answer to contain the final conclusion, so I can accept it?Tilt
I solved this just by an adding entry to my global gitignore file. Yes, not quite as clean, but, it works great.Amour

© 2022 - 2024 — McMap. All rights reserved.