Sharing files across branches in Git

后端 未结 6 1745

There are a bunch of files in my project that are sometimes modified but always shared among many different branches. Examples include build scripts, batch files that include p

6条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-07 05:57

    The other answers did not address my problem as cleanly as I would like, but they did push me to research more options.

    First off, git doesn't have the concept of tracking individual files, only whole repositories and branches.

    There is no built-in way to choose a set of files that should be maintained in source control and managed independently of other individual branches.

    In my project, virtually all the shared files are in one particular subdirectory. Whereas the rest of the source tree could change and should be managed by individual branches, this "configuration" fileset can be shared among various branches to keep the repository in a "live" state.

    I couldn't find the solution because I haven't read books on git and I didn't know the right search term. Git's solution for this situation is submodule.

    If, instead, my configuration information was spread among individual files that aren't contained in an individual directory, a submodule wouldn't be a good fit.

    In that case, a remote git repository should be set up and the files would be maintained in the separate repository using git-push.

提交回复
热议问题