用于Windows的git包管理?

car*_*mer 36 windows git bash msys msysgit

我在github上阅读wiki for git,它说msys2捆绑了pacman:https://github.com/git-for-windows/git/wiki/Package-management

但是当我调用它时:

$ pacman
bash: pacman: command not found
Run Code Online (Sandbox Code Playgroud)

有谁知道发生了什么?这个wiki指的是哪个git版本?有没有办法在Git for windows中为msys2安装额外的软件包?

Von*_*onC 29

问题397所述:

这是有意的.我们不用Git for Windows发送pacman.
如果您对完全成熟的软件包管理器维护环境感兴趣,那么您必须尝试使用Git for Windows SDK.

你在最新的git for Windows(2.5.3)中看到的bash ,它是一个比旧的msysgit更新的bash,只是执行git命令.
安装任何第三方软件包并不是一个成熟的Linux环境.

  • 是的,我不希望从git bash获得完整的linux体验,但是安装一些命令行实用程序以使在windows环境中工作变得更加痛苦将会很不错.我尝试使用Git for Windows SDK,看起来这就是我想要的.谢谢你的提示. (4认同)
  • 您可以手动提取Windows SDK的Git安装程序,然后编辑“安装”脚本`setup-git-sdk.bat`以限制已安装的软件包(不包括python和mingw构建工具)。这样可以减小安装尺寸,但仍允许您使用pacman升级现有的并安装其他软件包。不过,您必须从Git for Windows安装中复制“ git-bash.exe”和“ git-cmd.exe”(及其他?)。 (2认同)
  • 谨防。不要使用目录连接将现有的 git for windows 与 msys2 主系统链接起来。如果您卸载它,它将决定链接目录属于它,并删除您的整个主目录,包括“下载”等子目录。小心处理 msys2。我对自己失去的东西感到非常恶心。我不知道 git for windows SDK 是否也是如此,但是尝试从与 git for windows 集成的其他系统获取 pacman 时要小心。 (2认同)

N. *_*Ngo 14

Git for Windows(https://gitforwindows.org/https://git-scm.com/downloads)(有Git Bash),但不包括tree.tree可用于via pacman(程序包管理器),但仅当您安装"Git for Windows SDK " 时才可用(滚动到https://gitforwindows.org/的底部,它提供了从https://下载安装程序的链接)github.com/git-for-windows/build-extra/releases/latest)

这个SO:"用于Windows的git中的包管理?" 非常有帮助 在Windows的git中进行包管理?

同样如上面的SO所述,他们链接到这个git for windows issue [Pacman缺少新的2.5.2安装#397],它打算不包含pacman在默认安装中.

无论如何,我安装了"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
Run Code Online (Sandbox Code Playgroud)

在我的系统上,Git for Windows SDK安装在:C:\git-sdk-64,所以从我的Git for Windows Bash shell(没有安装树),我将它复制到tree.exe到它的/ usr/bin目录,例如

[MINGW64: Bash Terminal for Git for Windows]
cd /usr/bin
cp /c/git-sdk-64/usr/bin/tree.exe .
Run Code Online (Sandbox Code Playgroud)

现在我可以tree从两个Git Bash shell 运行v1.7.0.

因此,为了让其他人,也许我自己在未来的机器上更容易,我通过在我的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
...
Run Code Online (Sandbox Code Playgroud)

关键是,这是pacman从"msys"存储库中获取它(仅供参考:即使它说的是msys,它确实使用的是msys2),所以我看着/etc/pacman.d/mirrorlist.msys第一个镜像指向http://repo.msys2.org/msys/$arch/

因此,下次您需要一个不在 Git for Windows中的软件包时,可以从http://repo.msys2.org/msys/x86_64/(64位)或http://repo.msys2下载它们..org/msys/i686 /(32位)

例如,树v1.7.0-1的直接下载链接

仅供参考:Git SCM的Window下载地址为https://git-scm.com/download/,从Git for Windows GitHub获取最新信息(https://github.com/git-for-windows/git来自https:// github .com/git-for-windows/git/releases / link)

  • 如果你下载了包文件,你还需要pacman来安装它吗?Git for windows 不包含或支持 pacman ...除非您使用 git for windows sdk,其中包含 pacman 但不与常规 git for windows 安装集成。 (2认同)

小智 14

我不想从我已经在工作的 Git for Windows 安装中移动,所以我即兴创作了一点:

  1. 在其他地方安装适用于 Windows SDK 的 Git。为此,您需要 3 GB 以上的可用空间。
  2. 复制${git-sdk}/usr/bin/pacman.exe${git}/usr/bin
  3. 复制${git-sdk}/etc/pacman.conf${git-sdk}/etc/pacman.d${git}/etc
  4. 复制${git-sdk}/var${git}/

就这样。您现在可以打开 Git Bash 并运行pacman -S python以在现有 Git for Windows 设置上安装软件包。

您将需要对 Git for Windows 目录的写访问权限。此外,您pacman现在认为它安装了很多软件包(来自 SDK),但这并没有阻止我使用它。

  • 我收到 2 个错误:错误:无法初始化事务(无法锁定数据库)错误:无法锁定数据库:权限被拒绝我尝试安装 python 和 rsync (3认同)

Mik*_*ton 11

似乎有一种文档化的方法可以做到这一点,而无需安装 Git for Windows SDK(非常大)。当我在 GitHub issue #1912上询问所有这些时,PhilipOakley 给了我这个信息的链接。

这是 Git for Windows GitHub wiki 页面的当前文本:

正确安装在 MSYS2 内部

请注意,Git for Windows 不正式支持此方案

(这是不受支持的原因是没有志愿者来支持这种情况。)

本指南假定您需要适用于 Windows 的 64 位 Git 版本。

Git for Windows 基于 MSYS2,可以将git包安装到现有的 MSYS2 安装中。这意味着如果你已经在你的计算机上使用 MSYS2,你可以在不运行完整安装程序或使用便携式版本的情况下使用 Git for Windows。

但是请注意,这样做有一些注意事项。Git for Windows 创建了一些msys2-runtime尚未发送到上游的补丁。(这是计划好的,但在问题#284 中确定它可能不会发生。)这意味着您必须安装适用于 Windows 的 Git 定制,msys2-runtime以便在 MSYS2 中拥有一个完全工作的 git。

这里要采取的步骤:

  1. 打开 MSYS2 终端。

  2. 编辑/etc/pacman.conf之前[mingw32](我机器上的第 71 行),添加git-for-windows包存储库:

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

以及可选的相反架构的 MINGW -only 存储库(即 MINGW32 用于 64 位 SDK):

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

  1. 授权签名密钥(此步骤可能需要偶尔重复,直到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. 然后同步新的存储库

pacboy update

  1. 这会更新msys2-runtime,因此会要求您关闭窗口(不仅仅是退出 pacman 进程)。不要惊慌,只需关闭所有当前打开的 MSYS2 shell 和 MSYS2 程序。仔细检查任务管理器并pacman.exe在窗口关闭后杀死它仍在运行,因为它可以逗留。全部关闭后,再次启动新终端。

  2. 然后再次同步(更新包的非核心部分):

pacboy update

  1. 最后安装 Git/cURL 包:

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

  1. 最后,通过git --version在 MINGW64 shell 中执行检查是否一切正常,它应该输出类似git version 2.14.1.windows.1(或更新)的内容。

  • 此答案假设用户已经安装了现有且完整的 MSYS2。不过,我假设 OP 已安装适用于 Windows 的 Git。因此,上述说明不适用于 OP 的设置。 (3认同)
  • https://github.com/git-for-windows/git/issues/2688 中对此进行了讨论:步骤 4 不完整。 (2认同)

Mic*_*hen 10

"Git for Windows SDK" is 5.33GB compared to "Git for Windows" 691MB compared to "Portable Git" 275MB. I use the lean and mean Portable 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. Please read this official explanation:

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. 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.

Well, that's until I discover this file: /etc/package-versions.txt, the laundry list of matching msys2 packages and versions. Now there is a definitive source in github. Here is how I restore pacman in Portable Git:

Step 1: Run these commands to download /etc/pacman.conf and 3 packages: pacman, pacman-mirrors and msys2-keyring. These are .xz packages before msys2 switched to zstd. 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
Run Code Online (Sandbox Code Playgroud)

Step 2: Unpack them at the root then restore pacman with these commands:

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
Run Code Online (Sandbox Code Playgroud)

Step 3: The next two commands restore all matching metadata. 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
Run Code Online (Sandbox Code Playgroud)

Step 4: Now, is it too much to ask for 'make' and 'zip'?

pacman -S make zip
Run Code Online (Sandbox Code Playgroud)

Voilà, still just a 337MB mean little environment that can expand and upgrade!

  • 等待第3步大约需要5分钟 (2认同)
  • 安德烈是正确的。Msys2 于 2020 年 12 月切换到 zstd 软件包,这造成了先有鸡还是先有蛋的问题:当前版本的 Portable Git 不包含 zsdt,这会阻止在步骤 2 中运行 tar 命令。添加 zsdt (egg) 需要需要 zstd 的 pacman (chichen) (蛋)...因此,我修改了步骤1中的3个链接来下载.xz包。希望在 msys2 删除所有 .xz pacakge 之前,Portable Git 版本也能包含 zstd。 (2认同)

Wei*_*Liu 6

在 Windows 10 x86_64 1909 10.0.18363.752 上的 msys2 20190524 和 Windows 11 x86_64 21H2 10.0.22000.434 上的 msys2 20220128 上进行测试

使用适用于 Windows 的常规 Git。

  1. 安装msys2(版本20190524已测试。)或Git for Windows SDK. (尚未完全测试,但应该可以工作。)两者都包括 PacMan 和 Git。

使用 VFS for Git for Windows 或 Scalar for Git for Windows(又名 Microsoft git)。方法#1(有一些限制)

  1. 安装 VFSForGit ( https://github.com/microsoft/VFSForGit )。
  2. 安装 Microsoft git ( https://github.com/microsoft/git ),并启用“从命令行和第 3 方软件进行 Git”选项。
  3. 创建一个名为“git”的符号链接, msys64\usr\bin\指向C:\Program Files\Git\bin\git.exe. 在 cmd.exe 中执行以下命令,而不是在 bash 中。mklink git "C:\Program Files\Git\bin\git.exe"
  4. 克隆一个新的 gvfs 存储库。gvfs clone https://dev.azure.com/somebody/_git/somerepo只有gvfs命令不能在msys2上执行。
  5. 像正常使用 msys2 一样使用 git 命令。

使用 VFS for Git for Windows 或 Scalar for Git for Windows。方法#2

推荐使用Virtual Filesystem for Git(以前是 GVFS,官网https://vfsforgit.org/ )。版本 2.22 和 2.26 已测试。推荐使用Scalar(官方网站https://github.com/microsoft/scalar),也没有经过全面测试。

  1. 安装GVFSGit for Windows with GVFS patch。或者安装 Scalar for GitGit for Windows with Scalar patch. 不能两者都在同一台机器上。默认安装目标是C:\Program Files\Git.
  2. 将 msys2 x64 安装在C:\Program Files\Git. 默认情况下,它位于C:\msys64.
  3. 将 msys2 的文件和子文件夹(/etc 和 git 二进制文件除外。msys2 出厂时不带 git。)复制到 Windows VFS 版本的 Git,并将msys64 文件夹中的/etc/pacman.d和复制/etc/pacman.conf到 Git 安装文件夹,覆盖现有文件。它将 msys2 和 MinGW 运行时更新到最新版本。对于 PacMan,必要的文件是/usr/bin/pac* ; /etc/pacman.conf ; /etc/pacman.d/ ; /var ; /usr/bin/msys* ;。(未完全测试。)
  4. 设置终端应用程序。RunC:\Program Files\Git\bin\bash.exe将启动 Windows 版 Git 的 bash。运行C:\Program Files\Git\usr\bin\bash.exe将启动 msys2 的 bash。配置终端程序(例如超级终端)的bash路径。由于 Git 位于系统文件夹中,因此终端程序应以管理员身份运行
  5. 配置$PATH GVFS的环境变量。在 Git Bash 中运行此命令。export PATH=$PATH:/C/Program\ Files/GVFS或者export PATH=$PATH:"/C/Program Files/GVFS"。或者在控制面板的系统属性中设置GVFS的环境变量。重新登录即可生效。有时此配置不起作用,但 PacMan 仍然可以运行。
  6. 修复吃豆人。设置二进制文件的可执行权限。狐狸的例子。chmod +x /usr/bin/pacman ; pacman-key --init ; pacman-key --populate msys2 ; pacman-key --refresh-keys ; pacman --sync pacman --refresh --sysupgrade --sysupgrade --overwrite "*" 。使用该选项 --overwrite \*是因为某些软件包是由 Windows 版 Git 安装的,而不是 PacMan。