如何将第三方库导入到git中? [英] How do I import a third party lib into git?

查看:424
本文介绍了如何将第三方库导入到git中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究如何将一些第三方代码导入到git存储库中。
第三方代码是ST提供的stm32f10x_stdperiph_lib。

这个lib实际上是一系列正常的c文件(和头文件),当您执行 STM32 项目。



问题是,他们只提供它作为zip文件和
他们确实发布新版本,所以我想添加更多的控制权。



所以我的计划是写一个小脚本来做到这一点:


  1. 解压缩

  2. 获取一些文件(我不需要zip中的所有文件)

  3. 将所选文件导入到git存储库中

我的问题从最后一步开始,我如何导入和覆盖旧文件(并删除不再包含的文件)?

解决方案

您正在寻找的是供应商分支。假设您想要处理此代码并将供应商的更新与您自己的补丁合并,请按照以下步骤操作。

  git checkout -b vendor#创建一个供应商分支并检查它

这是一次性的事情。供应商分支及其仅包含来自第三方供应商的更新。您从不在供应商分支中工作,它包含供应商代码的清晰历史记录。关于供应商这个名字,它仅仅是我从CVS那里得到的术语,没有任何魔力。



现在我们将把供应商的最新版本放在那里。

  find。 -not -path * .git *和-not -path。 -delete#删除除git文件以外的所有内容
将第三方代码转储到项目目录#我将把它留给你
git add。 #添加所有文件,更改和删除
git commit -a -m'供应商更新版本X.YY'#提交
git标签'供应商X.YY'#可选,稍后可能会派上用场

我们先删除所有东西,以便git可以看到供应商删除的东西。 git能够看到删除和猜测移动的文件使得这个过程比使用Subversion简单得多。



现在你切换回你的开发(我假设为master)并合并到

  git checkout master 
git合并供应商

正常处理任何冲突。您的补丁版本现在与供应商保持一致。正常工作。



下一次有供应商的新版本,请重复此过程。这充分利用了git的优秀合并功能,让您的修补程序随供应商更新而保持最新。


I'm looking at how to import some third part code into a git repository. The third party code is the "stm32f10x_stdperiph_lib" that is provided by ST.

The lib is actually a bunch of normal c-files (and header-files) that you just include and build with when you do a STM32 project.

The problem is that they only provide it as a zip-file and they do release new versions, so I would like to add more control.

So my plan is to write a little script that does this:

  1. unzip
  2. grab some of the files (I don't need all the files in the zip)
  3. import the selected files into a git repository

My problems start at the last step, how do I import and overwrite the old files with the new ones (and remove files that are no longer included)?

解决方案

What you're looking for is a "vendor branch". Assuming you want to work on this code and merge the vendor's updates with your own patches, here's how you make that easy.

git checkout -b vendor    # create a vendor branch and check it out

That's a one time thing. The vendor branch and its ONLY going to contain updates from the 3rd party vendor. You never do work in the vendor branch, it contains a clean history of the vendor's code. There's nothing magic about the name "vendor" its just my terminology hold over from CVS.

Now we'll put the latest version from the vendor in there.

find . -not -path *.git* -and -not -path . -delete  # delete everything but git files
dump the 3rd party code into the project directory  # I'll leave that to you
git add .                              # add all the files, changes and deletions
git commit -a -m 'Vendor update version X.YY'   # commit it
git tag 'Vendor X.YY'                  # optional, might come in handy later

We delete everything first so that git can see things the vendor deleted. git's ability to see deletions and guess moved files makes this procedure far simpler than with Subversion.

Now you switch back to your development (I'm presuming master) and merge in the vendor's changes.

git checkout master
git merge vendor

Deal with any conflicts as normal. Your patched version is now up to date with the vendor. Work on master as normal.

Next time there's a new version from the vendor, repeat the procedure. This takes advantage of git's excellent merging to keep your patches up to date with vendor changes.

这篇关于如何将第三方库导入到git中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆