如何将 man 和 zip 添加到 Windows 上的“git bash”安装
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/38782928/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to add man and zip to "git bash" installation on Windows
提问by halloleo
I am using "git bash
"on Windows - that is git
for Windows via the integrated bash
. Apparently it uses the MINGW/MSYS underpinning. (Update from @VonC: It now uses msys2since msysgit is obsoletesince Q4 2015.)
我在 Windows 上使用“ git bash
”——即git
通过集成的bash
. 显然它使用了 MINGW/MSYS 基础。(来自@VonC 的更新:它现在使用 msys2,因为自 2015 年第四季度以来msysgit 已过时。)
So there are already a lot of MSYS tools installed - from awk
to zcat
. However I miss the man
command and zip
to compress multiple files into a zip file (unzip
exists!).
所以已经安装了很多 MSYS 工具——从awk
到zcat
. 但是我想念man
命令并将zip
多个文件压缩成一个 zip 文件(unzip
存在!)。
Where from can I install them? I do not want to install another copy of the MINGW system! Any way just to add some pre-compiled tools to the git bash
installation?
我可以从哪里安装它们?我不想安装另一个副本的MINGW系统!有什么办法可以在git bash
安装中添加一些预编译工具?
采纳答案by VonC
The zip
command can be install from GoW (Gnu On Windows). man
is not provided (too big).
该zip
命令可以从GoW (Gnu On Windows) 安装。man
没有提供(太大)。
It is to note however, that if you onlywant to add the zip
command from GoW, still the whole GoW system has to be downloaded and installed. Then you can delete the other commands from the bin
directory, however make sure to keep the needed dlls in the directory.
然而需要注意的是,如果你只想要添加zip
从GOW命令,还是整个GOW系统必须下载并安装。然后您可以从bin
目录中删除其他命令,但请确保将所需的 dll 保留在目录中。
回答by nokieng
Adding 7-zip to gitbash is easy.
将 7-zip 添加到 gitbash 很容易。
- Install 7-zip on windows.
- add 7-zip folder (
C:\Program Files\7-Zip
) to PATH
Ongitbash
exp:export PATH=$PATH:"C:\Program Files\7-Zip"
(temporary)
On Windows, adding PATH like image below (permanent)
- 在 Windows 上安装 7-zip。
- 加上7-ZIP文件夹(
C:\Program Files\7-Zip
)到PATH
在gitbash
EXP:export PATH=$PATH:"C:\Program Files\7-Zip"
(临时)
在Windows上,添加PATH像下面的图像(永久)
- duplicate a copy of 7z.exe to be zip.exe
- reopen gitbash again. done!
- 复制一份 7z.exe 为 zip.exe
- 再次重新打开 gitbash。完毕!
If you skip step 3. you still can call zip command as 7z
instead of zip
如果你跳过第 3 步,你仍然可以调用 zip 命令7z
而不是zip
I have just made it work! on my laptop.
我刚刚使它工作!在我的笔记本电脑上。
Conclusion: Gitbash is running base on windows Path, I think you can run any command that you have added to your Windows PATH.
By the way, don't forget to give feedback of your result if you try this.
结论:Gitbash 是基于 Windows Path 运行的,我认为您可以运行添加到 Windows PATH 中的任何命令。
顺便说一句,如果您尝试这样做,请不要忘记提供结果的反馈。
回答by Tung
I am so glad to share my experience on this issue that I haven't known for two years since the first day I played with Groovy. My method needs to have git
for Windows installed in Windows OS.
我很高兴分享我在这个问题上的经验,自从我第一天使用 Groovy 以来,我已经两年不知道了。我的方法需要git
在 Windows 操作系统中安装 Windows。
These steps are for installing 7z
command-line utility, which behaves a bit differently from zip
:
这些步骤用于安装7z
命令行实用程序,其行为与以下略有不同zip
:
- Download and install 7-Zip from its official website. By default, it is installed under the directory
/c/Program Files/7-Zip
in Windows 10 as my case. - Run git Bash under Administrator privilege and navigate to the directory
/c/Program Files/Git/mingw64/bin
, you can run the commandln -s "/c/Program Files/7-Zip/7z.exe" 7z.exe
- 从其官方网站下载并安装 7-Zip 。默认情况下,它安装
/c/Program Files/7-Zip
在 Windows 10的目录下,就像我的情况一样。 - 在管理员权限下运行 git Bash 并导航到目录
/c/Program Files/Git/mingw64/bin
,您可以运行命令ln -s "/c/Program Files/7-Zip/7z.exe" 7z.exe
I am pretty sure it could help you a lot. Trust me!
我很确定它可以帮助你很多。相信我!
回答by u4506703
git-archive
, is prepared without any installation, can create zip-archive.
git-archive
, 准备不用任何安装,可以创建zip-archive。
mkdir workrepo
cd workrepo
git init
cp -r [target_file_or_dir] .
git add .
git commit -m commit
git archive -o ../myarchive.zip @
cd ..
rm -rf workrepo
Following script may be usable:
zip.sh foo.zip target_file_or_dir
以下脚本可能可用:
zip.sh foo.zip target_file_or_dir
#!/usr/bin/bash
set -eu
unset workdir
onexit() {
if [ -n ${workdir-} ]; then
rm -rf "$workdir"
fi
}
trap onexit EXIT
workdir=$(mktemp --tmpdir -d gitzip.XXXXXX)
cp -r "" "$workdir"
pushd "$workdir"
git init
git add .
git commit -m "commit for zip"
popd
git archive --format=zip -o "" --remote="$workdir" HEAD
回答by Dylan Kirkby
You can mimic a small subset of man behavior in the shell by mapping man <command>
to <command> --help | less
您可以通过映射man <command>
到shell 中模拟人类行为的一小部分<command> --help | less
Unfortunately, on my machine bash aliases won't add flags to positional arguments, it will try to run the flag as a command and fail (alias man="$1 --help"
doesn't work).
不幸的是,在我的机器上,bash 别名不会向位置参数添加标志,它会尝试将标志作为命令运行并失败(alias man="$1 --help"
不起作用)。
And a function called man()
is not allowed!
并且man()
不允许调用函数!
Luckily a combination of bash functions and aliases can achieve this mapping. Put the code below in your ~/.bashrc (create one if it is not there). Don't forget to source ~/.bashrc
.
幸运的是,bash 函数和别名的组合可以实现这种映射。将下面的代码放在您的 ~/.bashrc 中(如果没有,请创建一个)。不要忘记source ~/.bashrc
。
# man command workaround: alias can't pass flags, but can't name function man
m() {
"" --help | less
}
alias man="m"
It doesn't get you the full man page, but if all you're looking for is basic info on a command and its flags, this might be all you need.
它不会为您提供完整的手册页,但如果您要查找的只是有关命令及其标志的基本信息,那么这可能就是您所需要的。
回答by NSjonas
Here's another, slightly different, set of instructions install zip for git bash on windows:
这是在 Windows 上为 git bash 安装 zip 的另一组略有不同的说明:
- Navigate to https://sourceforge.net/projects/gnuwin32/files/zip/3.0/
- Download
zip-3.0-bin.zip
- In the zipped file, in the
bin
folder, find the filezip.exe
. - Extract the file “zip.exe” to your "mingw64" bin folder (for me:
C:\Program Files\Git\mingw64\bin
) - Navigate to https://sourceforge.net/projects/gnuwin32/files/bzip2/1.0.5/
- Download
bzip2-1.0.5-bin.zip
- In the zipped file, in the
bin
folder, find the filebzip2.dll
- Extract
bzip2.dll
to your "mingw64" bin folder ( same folder -C:\Program Files\Git\mingw64\bin
)
- 导航到https://sourceforge.net/projects/gnuwin32/files/zip/3.0/
- 下载
zip-3.0-bin.zip
- 在压缩文件的
bin
文件夹中,找到文件zip.exe
. - 文件“zip.exe”解压到你的“mingw64” bin文件夹(对我来说:
C:\Program Files\Git\mingw64\bin
) - 导航到https://sourceforge.net/projects/gnuwin32/files/bzip2/1.0.5/
- 下载
bzip2-1.0.5-bin.zip
- 在压缩文件中,在
bin
文件夹中,找到文件bzip2.dll
- 解压
bzip2.dll
到您的“mingw64”bin 文件夹(同一文件夹 -C:\Program Files\Git\mingw64\bin
)
回答by wisbucky
You can install individual GNU tools from http://gnuwin32.sourceforge.net/packages.htmlsuch as zip
.
您可以从http://gnuwin32.sourceforge.net/packages.html安装单独的 GNU 工具,例如zip
.
Then add "/c/Program Files (x86)/GnuWin32/bin"
to PATH
in your startup script like .profile
, .bash_profile
, .bashrc
, etc.
然后添加"/c/Program Files (x86)/GnuWin32/bin"
到PATH
您的启动脚本一样.profile
,.bash_profile
,.bashrc
,等。
回答by sagekoda
Here are the steps you can follow.
以下是您可以遵循的步骤。
Go to the following link https://sourceforge.net/projects/gnuwin32/files/
Find out whatever command you are missing Here I need zip and bzip2 for zip command. Because zip command relies on bzip2.dll to run. Otherwise you will get error “error while loading shared libraries: ?: cannot open shared object file: No such file or directory”.
Unzip the downloaded files Here I am downloading “zip-3.0-bin.zip” for “zip.exe” and “bzip2-1.0.5-bin.zip” for “bzip2.dll” in the bin folder. /bin/.exe
Copy the command exe file into git-bash folder Here I am copying “zip.exe” and “bzip2.dll” to \Git\usr\bin.
找出您遗漏的任何命令 这里我需要 zip 和 bzip2 用于 zip 命令。因为 zip 命令依赖于 bzip2.dll 来运行。否则你会得到错误“加载共享库时出错:?:无法打开共享对象文件:没有这样的文件或目录”。
解压下载的文件 这里我在bin文件夹中下载“zip.exe”的“zip-3.0-bin.zip”和“bzip2.dll”的“bzip2-1.0.5-bin.zip”。/bin/.exe
将命令exe文件复制到git-bash文件夹这里我将“zip.exe”和“bzip2.dll”复制到\Git\usr\bin。
Reference Link https://ranxing.wordpress.com/2016/12/13/add-zip-into-git-bash-on-windows/
参考链接 https://ranxing.wordpress.com/2016/12/13/add-zip-into-git-bash-on-windows/
回答by Sheldon Campbell
In msys2, I restored the functionality of git help <command>
by installing man-db:
在 msys2 中,我git help <command>
通过安装 man-db恢复了 的功能:
|prompt> pacman -Syu man-db
|prompt> git help archive
For zip functionality, I also use git archive
(similar to yukihane's answer).
对于 zip 功能,我也使用git archive
(类似于 yukihane 的回答)。
回答by Setra R
I use choco
as my Windows Package Manager.
我choco
用作我的 Windows 程序包管理器。
I install 7zip with choco
using PowerShell
(you must be admin to use Choco)
我choco
使用 using安装 7zip PowerShell
(您必须是管理员才能使用 Choco)
PS > choco install 7zip.install
Open another gitbash
Terminal and locate the 7z.exe
executable
打开另一个gitbash
终端并找到7z.exe
可执行文件
$ which 7z
/c/ProgramData/chocolatey/bin/7z
Do a straight copy of 7z.exe
to zip.exe
and voila
直接复制7z.exe
tozip.exe
和voila
$ cp /c/ProgramData/chocolatey/bin/7z.exe /c/ProgramData/chocolatey/bin/zip.exe