I would like to track only a very restricted set of files, explicitly added to the repository using "git add -f". But how can I avoid having to use the "-f" again and again for files that are already in?
Sample:
% cat .gitignore
/*
% git status
On branch master
Your branch is up to date with 'origin/master'.
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
modified: playlists/README
% git add playlists/README
The following paths are ignored by one of your .gitignore files:
playlists
hint: Use -f if you really want to add them.
hint: Turn this message off by running
hint: "git config advice.addIgnoredFile false"
% git check-ignore -v playlists/README
% echo $?
1
% git commit -a -m "fixed some typo"
[master 039d616] fixed some typo
1 file changed, 1 deletion(-)
% git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
(use "git push" to publish your local commits)
nothing to commit, working tree clean
% git version
git version 2.37.2
The playlists/README was explicitly mentioned on the command line, and yet I have to use "-f"? git commit wasn't so picky.
Of course I checked the man page. It says
A gitignore file specifies intentionally untracked files that Git should
ignore. Files already tracked by Git are not affected; see the NOTES
below for details.
But the "NOTES below" didn't tell. playlists/README is already tracked, and yet it was affected. Please excuse if I am too blind to see.
Every insightful comment is highly appreciated
Additional information: Using
*
!*/
in .gitignore I get
% git status
On branch master
Your branch is up to date with 'origin/master'.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: .gitignore
modified: playlists/README
Untracked files:
(use "git add <file>..." to include in what will be committed)
code/
debian.old/
origin/
It took 3.75 seconds to enumerate untracked files. 'status -uno'
may speed it up, but you have to be careful not to forget to add
new files yourself (see 'git help status').
no changes added to commit (use "git add" and/or "git commit -a")
git add was very weird:
% git add .
warning: adding embedded git repository: code
hint: You've added another git repository inside your current repository.
hint: Clones of the outer repository will not contain the contents of
hint: the embedded repository and will not know how to obtain it.
hint: If you meant to add a submodule, use:
hint:
hint: git submodule add <url> code
hint:
hint: If you added this path by mistake, you can remove it from the
hint: index with:
hint:
hint: git rm --cached code
hint:
hint: See "git help submodule" for more information.
warning: adding embedded git repository: debian.old/raw-xbmc/raw-xbmc-13alpha8
warning: adding embedded git repository: origin
% git status
On branch master
Your branch is up to date with 'origin/master'.
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
modified: .gitignore
new file: code
new file: debian.old/raw-xbmc/raw-xbmc-13alpha8
new file: origin
modified: playlists/README
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
(commit or discard the untracked or modified content in submodules)
modified: debian.old/raw-xbmc/raw-xbmc-13alpha8 (modified content, untracked content)
Apparently unwanted files haven't been added.