简体   繁体   English

Package 管理在 Git 为 Windows (Git Bash)?

[英]Package management in Git for Windows (Git Bash)?

I'm reading the github wiki for git-for-windows and it says that msys2 bundles pacman: https://github.com/git-for-windows/git/wiki/Package-management我正在阅读 github wiki for git-for-windows,它说 msys2 捆绑了 pacman: https://github.com/git-for-windows/git/wiki/Package-management

But when I invoke it I get:但是当我调用它时,我得到:

$ pacman
bash: pacman: command not found

Does anyone have an idea what is going on?有谁知道发生了什么事?

Which git version does this wiki refer to?这个 wiki 指的是哪个 git 版本?

Is there a way to install additional packages to msys2 inside Git for windows?有没有办法在 Git 内为 windows 安装额外的包到 msys2?

As mentioned in issue 397 :第 397 期所述

This is intended.这是有意的。 We do not ship pacman with Git for Windows.我们不随 Git for Windows 提供 pacman。
If you are interested in a fully fledged package manager maintained environment you have to give the Git for Windows SDK a try.如果您对完全成熟的包管理器维护环境感兴趣,您必须尝试使用Git for Windows SDK

The bash that you see in the latest git for Windows (2.5.3) , which is a more recent bash than the old msysgit one , is only there to execute git commands.您在最新的 git for Windows (2.5.3) 中看到的bash 是比旧的 msysgit one 更新的 bash ,仅用于执行 git 命令。
It is not a full-fledged linux environment to install any third-party package.安装任何第三方软件包都不是成熟的 linux 环境。


Warning : dhj reports in the comments警告dhj评论中报告

Do not link your existing git for windows with the msys2 main system by using a directory junction.不要使用目录连接将现有的 git for windows 与 msys2 主系统链接。
If you uninstall it will decide that linked directory belongs to it and DELETE YOUR ENTIRE HOME DIRECTORY including sub-directories like "Downloads".如果您卸载它,它将决定链接目录属于它并删除您的整个主目录,包括“下载”等子目录。
Beware dealing with msys2.小心处理 msys2。

I don't know if the same is true for the git for windows SDK, but BE CAREFUL trying to get pacman from other systems integrated with git for windows.我不知道 git for windows SDK 是否也是如此,但是尝试从与 git for windows 集成的其他系统获取 pacman 时要小心。

Git for Windows ( https://gitforwindows.org/ or https://git-scm.com/downloads ) has Git Bash but it does not include tree . Windows 版 Git( https://gitforwindows.org/https://git-scm.com/downloads )有 Git Bash 但不包括tree

tree is available via pacman (Package Manager), but that is only available if you install "Git for Windows SDK " (scroll to the bottom of https://gitforwindows.org/ which provides a link to download installer for it from https://github.com/git-for-windows/build-extra/releases/latest ) tree可通过pacman (包管理器)获得,但只有在您安装“Git for Windows SDK ”时才可用(滚动到https://gitforwindows.org/的底部,它提供了从https下载安装程序的链接 : //github.com/git-for-windows/build-extra/releases/latest )

The accepted answer was very helpful.接受的答案非常有帮助。 They mention that git-for-windows was not meant to include pacman in the default install.他们提到git-for-windows并不意味着在默认安装中包含pacman

So I installed "Git for Windows SDK", then in its bash prompt (SDK-64) I ran the following to install current tree v1.7.0-1 (as of this posting Aug 30, 2018):因此,我安装了“Git for Windows SDK”,然后在其 bash 提示符 (SDK-64) 中运行以下命令来安装当前树 v1.7.0-1(截至 2018 年 8 月 30 日发布的这篇文章):

[SDK-64: Bash Terminal for Git for Windows SDK]
pacman -S tree
...
Proceed with installation? [Y/n] Y

On my system, Git for Windows SDK is installed under: C:\\git-sdk-64 , so from my Git for Windows Bash shell (which did not have tree installed), I copied it over tree.exe to its /usr/bin directory, eg在我的系统上,Windows SDK 的 Git 安装在: C:\\git-sdk-64 ,所以从我的 Windows Bash shell 的 Git(没有安装树),我通过 tree.exe 将它复制到它的/usr/bin目录,例如

[MINGW64: Bash Terminal for Git for Windows]
cd /usr/bin
cp /c/git-sdk-64/usr/bin/tree.exe .

Now I can run tree v1.7.0 from both Git Bash shells.现在我可以从两个 Git Bash shell 运行tree v1.7.0。

To make it even easier for others and maybe myself on a future machine, I looked at where pacman was getting the tree package from by running the following in my Git for Windows SDK Bash terminal:为了让其他人甚至我自己在未来的机器上更容易,我通过在我的 Git for Windows SDK Bash 终端中运行以下命令来查看pacman从哪里获取tree包:

$ pacman -S --info tree
Repository      : msys
Name            : tree
Version         : 1.7.0-1
Description     : A directory listing program displaying a depth indented list of files
Architecture    : x86_64
...

The key thing here is that pacman is getting tree from the "msys" repository (FYI: even though it says msys, it really is using msys2), so I looked at /etc/pacman.d/mirrorlist.msys and the first mirror points to http://repo.msys2.org/msys/$arch/这里的关键是pacman从“msys”存储库中获取tree (仅供参考:尽管它说的是 msys,但它确实使用的是 msys2),所以我查看了/etc/pacman.d/mirrorlist.msys和第一个镜像指向http://repo.msys2.org/msys/$arch/

So next time you want a package that is NOT in Git for Windows, you can download them from: http://repo.msys2.org/msys/x86_64/ (for 64-bit) or from http://repo.msys2.org/msys/i686/ (32-bit)因此,下一次你想有一个包,是不是在为Git的Windows,可以下载它们: http://repo.msys2.org/msys/x86_64/ (64位)或HTTP://repo.msys2 .org/msys/i686/ (32 位)

eg direct download link for tree v1.7.0-1例如树 v1.7.0-1 的直接下载链接

FYI: Git SCM's Window's download at https://git-scm.com/download/ pulls the latest from Git for Windows GitHub ( https://github.com/git-for-windows/git from the https://github.com/git-for-windows/git/releases/ link) FYI:Git的SCM的窗口的下载在https://git-scm.com/download/翻出从SVN为Windows GitHub上(最新https://github.com/git-for-windows/githttps://开头的github .com/git-for-windows/git/releases/链接)

I did not want to move from my already working Git for Windows installation so I improvised a bit:我不想从我已经在工作的 Git for Windows 安装中移动,所以我即兴创作了一点:

  1. Install Git for Windows SDK somewhere else.在其他地方安装适用于 Windows SDK 的 Git。 You'll need more than 3 GB of free space for that.为此,您需要 3 GB 以上的可用空间。
  2. Copy ${git-sdk}/usr/bin/pacman.exe to ${git}/usr/bin${git-sdk}/usr/bin/pacman.exe复制到${git}/usr/bin
  3. Copy ${git-sdk}/etc/pacman.conf and ${git-sdk}/etc/pacman.d to ${git}/etc${git-sdk}/etc/pacman.conf${git-sdk}/etc/pacman.d${git}/etc
  4. Copy ${git-sdk}/var to ${git}/${git-sdk}/var复制到${git}/

That's all.就这样。 You can now open your Git Bash and run pacman -S python to install packages on your existing Git for Windows setup.你现在可以打开你的 Git Bash 并运行pacman -S python来在你现有的 Git for Windows 设置上安装包。

You will need write access to Git for Windows directory.您将需要对 Git for Windows 目录的写访问权限。 Also, your pacman now thinks it has a lot of packages installed (from SDK) but it did not stop me from using it.此外,您的pacman现在认为它安装了很多软件包(来自 SDK),但这并没有阻止我使用它。

There seems to be a documented way to do this without having to install the Git for Windows SDK (which is very large).似乎有一种文档化的方法可以做到这一点,而无需安装 Git for Windows SDK(非常大)。 I was given the link to this info by PhilipOakley when I asked about all this on GitHub issue #1912 .当我在 GitHub issue #1912上询问所有这些时,PhilipOakley 给了我这个信息的链接。

Here's the current text of the Git for Windows GitHub wiki page about it:这是 Git for Windows GitHub wiki 页面的当前文本:

Install inside MSYS2 proper正确安装在 MSYS2 内部

Please note that this scenario is not officially supported by Git for Windows请注意,Git for Windows 不正式支持此方案

(The reason this is unsupported is that there are no volunteers to support that scenario.) (这是不受支持的原因是没有志愿者来支持这种情况。)

This guide assumes that you want the 64-bit version of Git for Windows.本指南假定您需要适用于 Windows 的 64 位 Git 版本。

Git for Windows being based on MSYS2, it's possible to install the git package into an existing MSYS2 installation. Git for Windows 基于 MSYS2,可以将git包安装到现有的 MSYS2 安装中。 That means that if you are already using MSYS2 on your computer, you can use Git for Windows without running the full installer or using the portable version.这意味着如果你已经在你的计算机上使用 MSYS2,你可以在不运行完整安装程序或使用便携式版本的情况下使用 Git for Windows。

Note however that there are some caveats for going this way.但是请注意,采用这种方式有一些注意事项。 Git for Windows created some patches for msys2-runtime that have not been sent upstream. Windows 版 Git 为msys2-runtime创建了一些尚未向上游发送的补丁。 (This had been planned, but it was determined in issue #284 that it would probably not be happening.) This means that you have to install Git for Windows customized msys2-runtime to have a fully working git inside MSYS2. (这是计划好的,但在问题#284 中确定它可能不会发生。)这意味着您必须安装 Git for Windows 自定义msys2-runtime才能在 MSYS2 中拥有一个完全工作的 git。

Here the steps to take:这里要采取的步骤:

  1. Open an MSYS2 terminal.打开 MSYS2 终端。

  2. Edit /etc/pacman.conf and just before [mingw32] (line #71 on my machine), add the git-for-windows packages repository:编辑/etc/pacman.conf并在[mingw32] (我机器上的第 71 行)之前添加git-for-windows软件包存储库:

[git-for-windows] Server = https://wingit.blob.core.windows.net/x86-64

and optionally also the MINGW-only repository for the opposite architecture (ie MINGW32 for 64-bit SDK):以及可选的相反架构的 MINGW-only 存储库(即 MINGW32 用于 64 位 SDK):

[git-for-windows-mingw32] Server = https://wingit.blob.core.windows.net/i686

  1. Authorize signing key (this step may have to be repeated occasionally until https://github.com/msys2/msys2/issues/62 is fixed)授权签名密钥(此步骤可能需要偶尔重复,直到https://github.com/msys2/msys2/issues/62被修复)

curl -L https://raw.githubusercontent.com/git-for-windows/build-extra/master/git-for-windows-keyring/git-for-windows.gpg | pacman-key --add - && pacman-key --lsign-key 1A9F3986

  1. Then synchronize new repository然后同步新的存储库

pacboy update

  1. This updates msys2-runtime and therefore will ask you to close the window ( not just exit the pacman process).这会更新msys2-runtime ,因此会要求您关闭窗口(不仅仅是退出 pacman 进程)。 Don't panic, simply close all currently open MSYS2 shells and MSYS2 programs.不要惊慌,只需关闭所有当前打开的 MSYS2 shell 和 MSYS2 程序。 Double-check Task Manager and kill pacman.exe it's still running after the window is closed, because it can linger.仔细检查任务管理器并杀死pacman.exe它在窗口关闭后仍在运行,因为它可以逗留。 Once all are closed, start a new terminal again.全部关闭后,再次启动新终端。

  2. Then synchronize again (updating the non-core part of the packages):然后再次同步(更新包的非核心部分):

pacboy update

  1. And finally install the Git/cURL packages:最后安装 Git/cURL 包:

pacboy sync git:x git-doc-html:x git-doc-man:x git-extra: curl:x

  1. Finally, check that everything went well by doing git --version in a MINGW64 shell and it should output something like git version 2.14.1.windows.1 (or newer).最后,通过在 MINGW64 shell 中执行git --version来检查一切是否顺利,它应该输出类似git version 2.14.1.windows.1 (或更新版本)的内容。

"Git for Windows SDK" is 5.33GB compared to "Git for Windows" 691MB compared to "Portable Git" 275MB. “Git for Windows SDK”为 5.33GB,而“Git for Windows”为 691MB,而“Portable Git”为 275MB。 I use the lean and mean Portable Git.我使用精益和刻薄的便携式 Git。 At first, it seems hopeless trying to restore and use pacman in the latter two flavors of Git (msys2), because Google excluded ALL metadata files in /var/lib/pacman/local.起初,在后两种版本的 Git (msys2) 中尝试恢复和使用 pacman 似乎没有希望,因为谷歌排除了 /var/lib/pacman/local 中的所有元数据文件。 Please read this official explanation:请阅读此官方解释:

https://wiki.archlinux.org/index.php/Pacman#.22Failed_to_commit_transaction_.28conflicting_files.29.22_error https://wiki.archlinux.org/index.php/Pacman#.22Failed_to_commit_transaction_.28conflicting_files.29.22_error

Without those metadata files, you don't know the exact collection and version of the msys2 packages Google selected to build a release of those 2 flavors of Git.如果没有这些元数据文件,您就不会知道 Google 为构建这两种 Git 版本而选择的 msys2 包的确切集合和版本。 If you force to install or copy the current version of msys2 packages, you run the risk of version mismatch with git binaries Google built and tested.如果您强制安装或复制当前版本的 msys2 软件包,则会面临与 Google 构建和测试的 git 二进制文件版本不匹配的风险。

Well, that's until I discover this file: /etc/package-versions.txt, the laundry list of matching msys2 packages and versions.好吧,直到我发现这个文件:/etc/package-versions.txt,匹配的 msys2 软件包和版本的清单。 Now there is a definitive source in github.现在github中有一个明确的来源。 Here is how I restore pacman in Portable Git:这是我在便携式 Git 中恢复 pacman 的方法:

Step 1: Run these commands to download /etc/pacman.conf and 3 packages: pacman , pacman-mirrors and msys2-keyring .步骤 1:运行这些命令下载 /etc/pacman.conf 和 3 个包: pacmanpacman-mirrorsmsys2-keyring These are .xz packages before msys2 switched to zstd.这些是 msys2 切换到 zstd 之前的 .xz 包。 See my comment below.看我下面的评论。

curl https://raw.githubusercontent.com/msys2/MSYS2-packages/7858ee9c236402adf569ac7cff6beb1f883ab67c/pacman/pacman.conf -o /etc/pacman.conf
for f in pacman-5.2.2-4-x86_64 pacman-mirrors-20201028-1-any msys2-keyring-1~20201002-1-any; 
 do curl https://repo.msys2.org/msys/x86_64/$f.pkg.tar.xz -o ~/Downloads/$f.pkg.tar.xz;
done

Step 2: Unpack them at the root then restore pacman with these commands:第 2 步:在根目录解压它们,然后使用以下命令恢复 pacman:

cd /
tar x --xz -vf ~/Downloads/msys2-keyring-1~20201002-1-any.pkg.tar.xz usr
tar x --xz -vf ~/Downloads/pacman-mirrors-20201028-1-any.pkg.tar.xz etc
tar x --xz -vf ~/Downloads/pacman-5.2.2-4-x86_64.pkg.tar.xz usr
mkdir -p /var/lib/pacman
pacman-key --init
pacman-key --populate msys2
pacman -Syu

Step 3: The next two commands restore all matching metadata.第 3 步:接下来的两个命令恢复所有匹配的元数据。 The second command is multi-line but still safe to cut and paste (be patient):第二个命令是多行的,但仍然可以安全地剪切和粘贴(请耐心等待):

URL=https://github.com/git-for-windows/git-sdk-64/raw/main
cat /etc/package-versions.txt | while read p v; do d=/var/lib/pacman/local/$p-$v;
 mkdir -p $d; echo $d; for f in desc files install mtree; do curl -sSL "$URL$d/$f" -o $d/$f;
 done; done

Step 4: Now, is it too much to ask for 'make' and 'zip'?第 4 步:现在,要求 'make' 和 'zip' 是否太多了?

pacman -S make zip

Voilà, still just a 337MB mean little environment that can expand and upgrade!瞧,仍然只有 337MB 意味着可以扩展和升级的小环境!

Tested on Windows 10 x86_64 1909 10.0.18363.752在 Windows 10 x86_64 1909 10.0.18363.752 上测试

Using regular Git for Windows.在 Windows 上使用常规 Git。

  1. Install msys2 (Version 20190524 is tested.) or Git for Windows SDK .安装msys2 (版本 20190524 已测试。)或Git for Windows SDK (Not fully tested, but it should work.) Both include PacMan and Git. (没有经过全面测试,但它应该可以工作。)两者都包括 PacMan 和 Git。

Using VFS for Git for Windows or Scalar for Git for Windows.使用 VFS for Git for Windows 或 Scalar for Git for Windows。

Virtual Filesystem for Git (formerly was GVFS. Official website https://vfsforgit.org/ ) is recommended.推荐使用 Git 虚拟文件系统(以前是 GVFS。官网https://vfsforgit.org/ )。 Version 2.22 & 2.26 are tested.版本 2.22 和 2.26 已测试。 Scalar (Official website https://github.com/microsoft/scalar ) is NOT recommended, neither fully tested.不推荐标量(官方网站https://github.com/microsoft/scalar ),也没有经过全面测试。

  1. Install GVFS and Git for Windows with GVFS patch . Git for Windows with GVFS patch安装GVFS Git for Windows with GVFS patch GVFSGit for Windows with GVFS patch Or install Scalar for Git and Git for Windows with Scalar patch .或者Git for Windows with Scalar patch安装Scalar for GitGit for Windows with Scalar patch NOT BOTH on the same machine.不是在同一台机器上。 The default installation destination is C:\\Program Files\\Git .默认安装目标是C:\\Program Files\\Git

  2. Install msys2 x64 somewhere else.在其他地方安装 msys2 x64。 By default, it is in C:\\msys64 .默认情况下,它位于C:\\msys64

  3. Copy files and subfolders of msys2 (except /etc and git binaries. The msys2 comes without git from factory.) to git for windows VFS edition, and copy /etc/pacman.d and /etc/pacman.conf in msys64 folder to Git folder, overwrite existing files.文件和msys2的子文件夹(除了在/ etc和git的二进制文件。该msys2来自不混帐从工厂)复制到git的窗户VFS版,并复制/etc/pacman.d/etc/pacman.conf的msys64文件夹中的Git文件夹,覆盖现有文件。 That will update msys2 and MinGW runtime to the latest version.这会将 msys2 和 MinGW 运行时更新到最新版本。 For PacMan, the necessary files are /usr/bin/pac* ; /etc/pacman.conf ; /etc/pacman.d/ ; /var /usr/bin/msys* ;对于 PacMan,必要的文件是/usr/bin/pac* ; /etc/pacman.conf ; /etc/pacman.d/ ; /var /usr/bin/msys* ; /usr/bin/pac* ; /etc/pacman.conf ; /etc/pacman.d/ ; /var /usr/bin/msys* ; .(Not fully tested.) .(未完全测试。)

  4. Setup terminal applications.设置终端应用程序。 Run C:\\Program Files\\Git\\bin\\bash.exe will launch the bash of Git for Windows.运行C:\\Program Files\\Git\\bin\\bash.exe将启动 Windows 版 Git 的 bash。 Run C:\\Program Files\\Git\\usr\\bin\\bash.exe will launch bash of msys2.运行C:\\Program Files\\Git\\usr\\bin\\bash.exe将启动 msys2 的 bash。 Configure the path of bash for terminal programs, such as Hyper Terminal .为终端程序配置bash的路径,例如超级终端 Since Git is in a system folder, terminal programs should be Run as administrator .由于 Git 位于系统文件夹中,因此终端程序应以管理员身份运行

  5. Config $PATH the environmental variable for GVFS.为 GVFS 配置 $PATH 环境变量。 Run this command in Git Bash.在 Git Bash 中运行此命令。 export PATH=$PATH:/c/Program\\ Files/GVFS or export PATH=$PATH:"/c/Program Files/GVFS" . export PATH=$PATH:/c/Program\\ Files/GVFSexport PATH=$PATH:"/c/Program Files/GVFS" Or set environmental variables for GVFS in system property of the control panel.或者在控制面板的系统属性中为 GVFS 设置环境变量。 Re-login to take effect.重新登录生效。 Sometimes this configuration does not work, but PacMan can still run.有时这种配置不起作用,但 PacMan 仍然可以运行。

  6. Fix PacMan.修复吃豆人。 Set executable permission for binaries.设置二进制文件的可执行权限。 Fox example.狐狸的例子。 chmod +x /usr/bin/pacman ; pacman-key --init ; pacman-key --populate msys2 ; pacman-key --refresh-keys ; pacman --sync pacman --refresh --sysupgrade --sysupgrade --overwrite "*" chmod +x /usr/bin/pacman ; pacman-key --init ; pacman-key --populate msys2 ; pacman-key --refresh-keys ; pacman --sync pacman --refresh --sysupgrade --sysupgrade --overwrite "*" . chmod +x /usr/bin/pacman ; pacman-key --init ; pacman-key --populate msys2 ; pacman-key --refresh-keys ; pacman --sync pacman --refresh --sysupgrade --sysupgrade --overwrite "*" Use the option --overwrite \\* because some packages were installed by Git for Windows instead of PacMan.使用选项--overwrite \\*因为有些软件包是由 Git for Windows 而不是 PacMan 安装的。

pacman is compressed using zstd now. pacman 现在使用 zstd 压缩。 So updated @michael-chen 's scenario (i use wsl's unzstd):所以更新了@michael-chen 的场景(我使用 wsl 的 unzstd):

for f in pacman-6.0.1-25-x86_64.pkg.tar.zst pacman-mirrors-20221016-1-any.pkg.tar.zst msys2-keyring-1~20221024-1-any.pkg.tar.zst;   do curl https://repo.msys2.org/msys/x86_64/$f -o ~/Downloads/$f; done
cd /
tar --use-compress-program=unzstd -xvf ~/Downloads/msys2-keyring-1~20221024-1-any.pkg.tar.zst usr
tar --use-compress-program=unzstd -xvf ~/Downloads/pacman-mirrors-20221016-1-any.pkg.tar.zst etc
tar --use-compress-program=unzstd -xvf ~/Downloads/pacman-6.0.1-25-x86_64.pkg.tar.zst usr
mkdir -p /var/lib/pacman
pacman-key --init
pacman-key --populate msys2
pacman -Sy
export URL=https://github.com/git-for-windows/git-sdk-64/raw/main
cat /etc/package-versions.txt | while read p v; do d=/var/lib/pacman/local/$p-$v; mkdir -p $d; echo $d; for f in desc files install mtree; do curl -sSL "$URL$d/$f" -o $d/$f; done; done

Copying pacman from msys2 works for me, at the end most people forget that you can use pacman for self update as pacman -Syy msys/pacman从 msys2 复制 pacman 对我有用,最后大多数人忘记了您可以使用 pacman 作为pacman -Syy msys/pacman进行自我更新

  1. Run in msys pacman -Ql pacman在 msys pacman -Ql pacman中运行

  2. Copy files listed that match复制列出的匹配文件

  • /etc/*.conf /etc/*.conf
  • /usr/bin /usr/bin
  • /usr/include /usr/包括
  • /usr/lib /usr/lib
  • /var/lib /var/lib
  1. And copy databases as well以及复制数据库
  • /etc/pacman /etc/pacman
  1. At this point I already have a working pacman,I check it with pacman -Ss pacman but there are missing files so I run self refresh pacman -Syy msys/pacman此时我已经有一个可用的 pacman,我用pacman -Ss pacman检查它,但文件丢失,所以我运行 self refresh pacman -Syy msys/pacman

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM