git: How do you add an external directory to the repository?

前端 未结 8 1759
旧巷少年郎
旧巷少年郎 2020-12-02 10:16

I want to add an external directory to an existing repository.

External Dir: /home/some/directory

Working Dir: /htdocs/.git

If I attempt the followin

相关标签:
8条回答
  • 2020-12-02 11:11

    There's a really simple solution to this.

    Let say you're Git-repo is in /var/data/my-app and you want to add /var/data/public/ to that repo. You can't use 'add' because Git won't add resources outside of the repo's root directory. So..

    Solution:

    1. Move the /var/data/public/ directory into your Git-repo root (/var/data/my-app).

    2. Create a sym-link (symbolic link) inside of /var/data/public to the /var/data/my-app/public folder, using: ln -s source_file_or_directory virtual_file_or_directory

    Then, just add the moved file or directory to Git using git add in the normal fashion. Your Git source control is now tracking the desired file/folder, and your sym-link in the external directory assures that the file/folder is accessible to whatever else!

    0 讨论(0)
  • 2020-12-02 11:14

    If I need to do something like that I would normally move that external file or directory into my git repo and symlink it's original location to the new one.

    mv /home/some/directory /htdocs/directory
    ln -s /htdocs/directory /home/some/
    git add ./directory
    

    I use this technique when I am developing a plug-in for an application that I want to keep under version control but have to store in a specific location.

    0 讨论(0)
提交回复
热议问题