git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Sharing a file between projects

From
Jonathan Nieder <jrnieder@gmail.com>
Date
May 24, 2010, 08:55 UTC
Message-ID
<20100524085533.GA25227@progeny.tock>
In-Reply-To
<D3671E72-7B04-446B-86A8-48761FD476E4@gmail.com>
Patrick Rutkowski wrote:
> I also don't want to have to manually make sure that foo.cfg is
> synced among all three projects.

Give foo.cfg its own repo, since it seems it is independently useful. Then you could use it from your other projects P1, P2, P3 in one of the following ways:

a. Installation script (‘make install’) copies foo.cfg to some
   standard filename, such as /usr/share/foo/foo.cfg or /etc/foo.cfg.
   Then use it from there, e.g. by tracking an ordinary symlink
   /etc/foo.cfg -> foo.cfg in the P1, P2, P3 trees.
b. Occasionally pull from the foo.cfg project into P1, P2, and P3.
c. Teach P1, P2, P3 build scripts to clone the foo.cfg repo and grab
   foo.cfg
d. Add the foo.cfg repo as a submodule of the P1, P2, and P3 repos.
Examples:
 a. most libraries.  I guess /usr/lib/tclConfig.sh and
    /usr/lib/pkgconfig/* are good examples.
 b. Debian X build system: http://git.debian.org/?p=pkg-xorg/xsfbs.git
 d. gnulib: http://git.savannah.gnu.org/cgit/gnulib.git/tree/users.txt
Relevant git features:
 a. If there is a symlink in the worktree, the only information that
    git will notice is “symlink to <target>”.  The content of the
    target does not enter the tracked tree.
 b. Merging from an independent project is a perfectly okay way to add
    files.  Merging again is a good way to update them.
    Merging changes back to a smaller project is not so well
    supported[1].
 d. Using submodules works like this:
    . ‘git clone --recursive’ to grab all the relevant files at once
    . Do work within submodules and ‘git push’ to publish your work
    . Git will remember the ‘last tested commit’ so new changes to
      foo.cfg do not break new clones of P1, P2, and so on until
      someone in each project explicitly acks them.
    . See git-submodule(1) for details (and please let us know about
      confusing or missing details in that manual).

Thoughts? Jonathan

[1] Suppose I have been working for a while as in case (b) above [time flows from left to right]:

 foo.git:    F --- G --- H --- I
                    \           \
 P1: A --- B --- C - M --- D --- N --- O

Now I make a change to foo.cfg (Q) and commit and push it in P1.git, even though it ought to have been done in foo.git so it could be used by P2 and P3, too. Oops.

 foo.git:    F --- G --- H --- I
                    \           \
 P1: A --- B --- C - M --- D --- N --- O --- Q

Now I could try to merge P1 into foo.git, but unfortunately the result would be a commit incorporating all development from both branches, including the files from P1 that are _not_ foo.cfg.

I use git-filter-branch(1) to recover, producing an alternate history tracking only changes to foo.cfg:

      F --- G --- H --- I
             \           \
        A' ---M'----------N' --- Q'
Uh, the desired history looks more like the following:
     F --- G --- H --- I --- Q'

but git filter-branch --prune-empty is not sophisticated enough to do that. Maybe someone can chime in with a script for this situation.

Now I merge the rewritten history into foo.git:
 foo.git:    F --- G --- H --- I --- Q'
                    \           \
 P1: A --- B --- C - M --- D --- N --- O --- Q

and use ‘merge -s ours’ to indicate that the new changes have already been incorporated into P1.

 foo.git:    F --- G --- H --- I ------ Q' ---.
                    \           \              \
 P1: A --- B --- C - M --- D --- N --- O --- Q - R
Previous: Patrick Rutkowski
Message 2 of 2 in “Sharing a file between projects”
  1. Patrick RutkowskiMay 22, 2010
  2. Jonathan NiederMay 24, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.