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

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

问题描述

我正在研究如何将某些第三方代码导入 git 存储库.第三方代码是ST提供的stm32f10x_stdperiph_lib".

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.

lib 实际上是一堆普通的 c 文件(和头文件),当您执行 STM32 项目.

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.

问题是他们只将其作为 zip 文件提供,并且他们确实发布了新版本,所以我想添加更多控制.

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. 解压
  2. 获取一些文件(我不需要 zip 中的所有文件)
  3. 将选定的文件导入到 git 存储库中

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

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

那是一次性的事情.供应商分支及其仅包含来自第 3 方供应商的更新.您永远不会在供应商分支中工作,它包含供应商代码的干净历史记录.供应商"这个名字并没有什么神奇之处,它只是我从 CVS 中保留下来的术语.

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

我们首先删除所有内容,以便 git 可以看到供应商删除的内容.git 查看删除和猜测移动文件的能力使这个过程比使用 Subversion 简单得多.

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.

现在你切换回你的开发(我假设是master)并合并供应商的更改.

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

git checkout master
git merge vendor

正常处理任何冲突.您的修补版本现在是供应商的最新版本.像往常一样在 master 上工作.

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

下次有来自供应商的新版本时,请重复该过程.这利用了 git 出色的合并功能,使您的补丁与供应商更改保持同步.

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天全站免登陆