I have a remote bare repo on my server. I want the server to always have the current working tree as a real directory in the system.
I am using the post-receive
git-hook with a command to build the working tree and to override the old tree:
git archive master | tar -x -C /dir/to/my/project/
However, this approach has a problem: It does not delete files that were deleted/moved in the repo.
I could simply erase the whole project directory but I want to keep all files that are ignored in my .gitignore.
I tried to write a script to delete all files that are not ignored but it takes minutes to process.
Is there a way to replicate the working tree without erasing ignored files?
CodePudding user response:
You can either add worktrees with the convenience command (not really the best plan, but probably workable) or implement the parts you need yourself with core commands (guaranteed to always work the same).
The index is a manifest, a list of pathnames and pointers to repo content and cached filesystem metadata for the filesystem copy at that path.
GIT_WORK_TREE=/path/to/your/checkout GIT_INDEX_FILE=/path/to/your/manifest \
git read-tree -um $commit:$dir
Where you put the work tree and index is entirely up to you, Git's core doesn't care, just tell it (as I've done here).
Docs for the $commit:$dir
revision syntax
git read-tree
is the core command underlying checkout, merge, hard resets, and anything of the kind.