1

I'm really struggling to understand git, so here's a tighter rephrasing of a previous question I had asked. I'm going to explain a hypothetical scenario, detailing what I think happens when you download some code using git and install it on a machine, and hopefully somebody can tell me which part I am incorrect about!

  1. I run git clone git://github.com/foo/foo.git
  2. This creates a local directory foo, and downloads the source code and git data
  3. This source code effectively contains all the versions of the software: source files, header file, and git data for the different versions
  4. I run git checkout release-1.0
  5. This tells my system that I want to deal with version 1.0 of the software
  6. I run make, which compiles the code for version 1.0
  7. This creates a library called libfoo.so.1
  8. I run make install, which installs the library
  9. This copies over libfoo.so.1 into the directory /usr/local/lib
  10. It also copies over the header file foo.h into the directory /usr/local/include
  11. This header file is the version of foo.h that corresponds to version 1.0 of the software
  12. I now also want to install version 2 of the software, so I run git checkout release-2.0
  13. This tells my system that I want to deal with version 2.0 of the software
  14. I run make, which compiles the code for version 2.0
  15. This creates a library called libfoo.so.2
  16. I run make install, which installs the library
  17. This copies over libfoo.so.2 into the directory /usr/local/lib
  18. It also copies over the header file foo.h into the directory /usr/local/include
  19. This header file is the version of foo.h that corresponds to version 2.0 of the software
  20. I now try to create a project which depends on version 2.0 of the software, and link it to libfoo.so.2 which is at /usr/local/lib, and include foo.h which is at /usr/local/include
  21. This project compiles and runs fine
  22. I now try to create a project which depends on version 1.0 of the software, and link it to libfoo.so.1 which is at /usr/local/lib, and include foo.h which is at /usr/local/include
  23. This project does not compile ok, because foo.h is the header file for version 2.0 of the software, not version 1.0.

So, the thing I am puzzled about is how you can have two versions of some software installed on your machine. The actual library files libfoo.so.1 and libfoo.so.2 are both created and can be linked to by two different projects, but there is only one version of foo.h installed on the local machine. Therefore, only the version which was installed the latest will have the correct header file, because the two versions require different versions of foo.h.

Please can somebody explain where I am getting confused? Thanks!

2 Answers 2

5

It's not a git problem at all. In fact, it has nothing to do with Git or even a program you're trying to install. It's just a version conflict.

To solve this type of problems, there are many possible approaches:

  • Installing each version in a separate virtual machine
  • ... in a separate Docker containers
  • Using smart package managers like nix which would allow you to have any number of versions of a same program installed
  • probably something else...

In cases like this, I prefer use Docker since its' containers are lightweight (compared to virtual machines). This way, I can have any kind of environment to build and run any program. Any dependencies are installed directly in a container, so when I run my build against it, everything is already there, and my host machine is not polluted with random software.


Regarding to your approach with Git. You're doing it right, but it would work anyway exactly because you can't have two versions of a same header file simultaneously. You seem to understand the problem.

0

To my understanding (and correct me if I am wrong - sorry for the recursion):

  1. No, only for the current branch

  2. Selects branch

Git is tree-like in nature, but the main purpose is to progress back to the Master - which is the trunk of the tree.

What is likely happening is that you overwrite the local files when running make. Read more here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.