Git - 如何处理符号链接 [英] Git - how to handle symlinks

查看:223
本文介绍了Git - 如何处理符号链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有以下结构:

供应商
模块A
模块B
模块C
应用程序
代码
模块
核心模块1
核心模块2
模块A(符号链接到供应商)
模块B(符号链接到供应商)
模块C(符号链接到供应商)

有一个主应用程序目录,其中包含应用程序中的所有核心代码。此外,还有一个供应商目录,其中包含模块,它们被链接到主应用程序目录中,因此被集成。



重要的是,供应商目录和主应用程序目录都是版本控制的在同一个存储库中。



因此,我应该让git继续存储符号链接,或者找到一种方法让它忽略符号链接?

解决方案

只要所有开发人员使用的操作系统都支持它,Git就可以处理符号链接。因为你依赖这些符号链接,所以我会假定你的开发环境都支持符号链接。



决定是否应该在你的git仓库中包含某些东西(符号链接或否则)考虑以下内容:


  • 它是由存储库中的某个工具或其他进程生成的文件吗?如果是这样,最好忽略它并让每个用户生成文件,以便它们始终具有最新版本。

  • 文件是特定于特定用户的开发环境还是一个用于所有环境?如果它是一个特定用户环境的怪癖,就像忽略Emacs备份文件的配置,它不属于回购站。如果它是所有开发人员需要的东西,并且/或者构建生产应用程序所需的东西,它应该放在存储库中。



在你的情况下,似乎没有生成符号链接,并且在所有环境中都需要它们,因此将它们放入存储库应该没问题。

然而,在创建它们时一定要将它们创建为相对符号链接而不是绝对符号链接,这样无论存储库的克隆位置如何,它们都可以工作。最简单的方法是将目录切换到Modules目录并从那里创建符号链接:

  cd App / Code /模块
ln -s../../../Vendors/Module A模块A


What is the correct way to handle symlinks in git?

I have the following structure:

Vendors
  Module A
  Module B
  Module C
App
 Code
   Modules
     Core Module 1
     Core Module 2
     Module A (symlinked to vendors)
     Module B (symlinked to vendors)
     Module C (symlinked to vendors)

There is a a main App directory which contains all of the core code in the application. Additionally there is a vendor directory that contains modules which get symlinked into the main app directory and therefore integrated.

Importantly, both the vendor directory and the main app directory are both versioned in the same repository.

Therefore, should i let git keep storing the symlinks, or find a way to have it ignore symlinks?

解决方案

Git can handle symlinks just fine as long as the operating system used by all developers supports them. Since you depend on having these symlinks present I will assume that your development environments all support symlinks.

To decide if something should be included in your git repository or not (symlink or otherwise) consider the following:

  • Is it a file generated by some tool or other process in the repository? If so, it's best to ignore it and let each user generate the file, so that they will always have the latest version.
  • Is the file specific to a particular user's development environment, or one that is used in all environments? If it's a quirk of a particular user's environment, like a configuration to ignore Emacs backup files, it doesn't belong in the repo. If it's something all developers will need, and/or something that's needed to build the application for production, it should go in the repository.

In your case it seems like the symlinks are not generated and they are needed in all environments, so putting them in the repository should be fine.

However, when creating them be sure to create them as relative symlinks rather than absolute symlinks, so that they'll work regardless of where the repository is cloned. The easiest way to do this is to change directory into the Modules directory and create the symlink from there:

cd App/Code/Modules
ln -s "../../../Vendors/Module A" "Module A"

这篇关于Git - 如何处理符号链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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