I am using git to version control user-configuration files on my Linux home PC.
Git refuses to add these two files to the user-configuration repository:
~/.emacs.d/.cache/bookmarks
~/.emacs.d/.cache/recentf
Directory .emacs.d/ contains a .git repository. All files outside of .emacs.d/ where added without issue.
Is there a way to track the two files as if they where not in another git repository? Git submodule seems like over kill.
I am running git version 2.33.1 on Fedora 35 Workstation.
Here are some other things that might be relevant:
gitc alias is defined in my .bashrc file:
alias gitc='/usr/bin/git --git-dir=$HOME/config_repo --work-tree=$HOME'
Git add executes and returns silently but nothing is added:
$ gitc add .emacs.d/.cache/bookmarks .emacs.d/.cache/recentf
$ gitc status
On branch clean_install_orphan
nothing to commit (use -u to show untracked files)
The .emacs.d/.cache/ files are not listed in the tracked committed files:
$ gitc ls-files .emacs.d/.cache/bookmarks .emacs.d/.cache/recentf
returns nothing.
After editing the .emacs.d/.cache/recentf file, it is not listed in:
$ gitc status
because it was never added.
Add force option gets similar results:
$ gitc add -f .emacs.d/.cache/bookmarks .emacs.d/.cache/recentf
The files exists and the paths are correct:
$ cd ~
$ ls -l .emacs.d/.cache/recentf
-rw-------. 1 wolfv wolfv 2999 Jan 11 00:41 .emacs.d/.cache/recentf
$ ls -l .emacs.d/.cache/bookmarks
-rw-r--r--. 1 wolfv wolfv 1663 Jan 2 10:39 .emacs.d/.cache/bookmarks
There is no .gitignore or .gitignore_global file in HOME.
The repository's exclude file is empty:
$ more config_repo/info/exclude
# git ls-files --others --exclude-from=.git/info/exclude
# Lines that start with '#' are comments.
# For a project mostly in C, the following would be a good set of
# exclude patterns (uncomment them if you want to use them):
# *.[oa]
# *~
The --bare option was used when initializing the repository:
$ git init --bare $HOME/config_repo
which should not cause the problem.
.cache is not a symlink:
$ ls -la .emacs.d/
..
drwxr-xr-x. 1 wolfv wolfv 452 Jan 11 00:41 .cache
..
CodePudding user response:
You mention that:
Directory
.emacs.d/contains a.gitrepository.
This is the problem. Git will refuse to store a Git repository within a Git repository. This is for a number of good reasons. You can in theory sort of work around it by renaming the .git to, e.g., .got and then adding that, but don't do that.
If you attempt to git add a Git repository to another Git repository, the "outer" repository will wind up containing a reference to (not a copy of) the inner repository. Internally, this reference takes the form of a thing Git calls a gitlink. The gitlink is a crucial part of a Git submodule, but is not all of a submodule: for a submodule to "work right", there's a second crucial part that Git stores in .gitmodules. The git add command will create or update a gitlink, but will not create the correct .gitmodules file.
You can either:
- stop using a separate Git repository within
.emacs.d, or - just treat this as two repositories (with or without treating
.emacs.das a submodule) and back up and/or replicate both Git repositories.
To treat .emacs.d as a submodule, use git submodule add at least once to create the .gitmodules file in the superior (or superproject ) repository whose database resides in --git-dir=$HOME/config_repo. In this case that would be gitc submodule add, which probably works, but I don't know if the potential interaction issues with --git-dir arguments vs submodules (which themselves use --git-dir internally) are normally tested when Git is built. To avoid using it as a submodule, just carry on as you are doing already and do not gitc add .emacs.d.
