1

In my projects, I used 3rd party git repo as libraries. And I add them in my .gitignore list so that I can pull the libraries separately. Is there a way to bind certain commit in the branch of my project to a certain commit in the 3rd party library?

weijia_yu
  • 965
  • 4
  • 14
  • 31
  • That sounds like a use case for submodules. Or subtrees possibly. I've seen people hate on both, so you might want to google the documentation for each and see which looks more suitable for you – Mark Adelsberger Sep 25 '17 at 18:42
  • Yeah, I also have heard submodule can be very complicated, so I tried to avoid that. – weijia_yu Sep 25 '17 at 21:09

1 Answers1

0

Binding a specific commit to a Git repo is more for submodule than subtree: I have illustrated the differences between the two here.

So add your third-party library repo to your current repo

git submodule add /url/to/library library

Then checkout the exact commit you want

cd library
git checkout <SHA1>

Finally, go back to the main repo and record the new gitlink (a special entry in the index of the main repo)

cd ..
git add .
git commit -m "new library SHA1"
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250