Git submodules — exclude specific files/directories

前端 未结 2 1687
温柔的废话
温柔的废话 2021-02-19 14:42

I\'m attempting to use Gits \'submodules\' feature to include 3rd party code in a project. I only need a couple of files from the submodule and wish to exclude all the docs, etc

相关标签:
2条回答
  • 2021-02-19 15:24

    In my submodule I had an /examples folder I wanted deleted locally to prevent those files being seen by an autogenerated makefile; origin had to remain oblivious to the deletion.

    In git CLI:

    git update-index --assume-unchanged <path/to/file>

    To track local changes once again:

    git update-index --no-assume-unchanged <path/to/file>

    Or in SourceTree, create a custom action as per Fabian Blechschmidt's answer.

    NOTE This is not the same as "Stop tracking", where origin will indeed also stop tracking the file on commit - not what you want.

    0 讨论(0)
  • 2021-02-19 15:28

    A git submodule is a git repository embedded inside another git repository. Other than that there's nothing special about it -- a submodule behaves the same way as any other git repository. You get all the files and all the history associated with the repository when you clone it.

    If you just want a couple of files and you're not interested in tracking the change history of the third-party project, maybe you should just copy the specific files into your project and call it done.

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