Question

I have a project that uses two library that are maintained seperately. To avoid the mess of manually copying files over every time the library changes, I managed to create two subtree using this example from github.

I have my own code in the root of this working directory. I also have foolib/ and barlib/ as subtrees from two other repos. Suppose I want to see if I can use version 1.20 of foolib instead of the master because I know that one's good and won't change. Then maybe I want to see if 1.21 is any better. My thinking is that if I do git checkout foolib-1.20 will put version 1.20 code in foolib/ for me. That doesn't happen. Instead the whole working directory is replaced with foolib 1.20. This is not very helpful and seems to negate the usefulness of git subtree.

Was it helpful?

Solution

If you need to reference specific commits for your libraries, it would be better to use submodules.

That way, your parent directory can record references to those library repos, and to their exact commit.
Note that would not prevent you to chage the libraries directly from your working tree (provided you commit and push those libraries back to their upstream repo, and commit your parent repo: see "True nature of submodules")

However, submodules can include some gotchas (see "how exactly does git submodule work")

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top