git - 编译或下载静态版本的 git

我需要在没有 root 权限的 32 位 ubuntu 机器上运行 git 版本。 PC 在教室里,我没有 root 权限来安装,例如 curl 。

对于 darcs,这个步骤很简单,因为我可以直接从网站下载静态二进制文件:
http://teratorn.org/code/darcs-2.8.0-linux-ghc7.0.4-CURL-packed.by.ermine.tar.bz2

我按照上一个问题中给出的说明进行操作:compile-git-for-32-bit-linux-on-shared-hosting

我使用了上一篇文章中的以下命令来配置构建:

./configure --prefix=/home/stephan/git-static CFLAGS="${CFLAGS}
-static -m32"

但是,这会导致以下错误:

checking whether the C compiler works... no
configure: error: in `/home/stephan/Downloads/git-1.7.12.4':
configure: error: C compiler cannot create executables
See `config.log' for more details

真的没有网站可以下载 32 位系统的静态 git 二进制文件吗?

我必须在 VM 中安装 32 位 ubuntu 吗?

最佳答案

自己静态编译一份 Git 并不难,您可以按照这些说明进行操作。我使用了 Musl 交叉编译器,因此生成的二进制文件是完全静态的;他们甚至不与 glibc 链接(这是一个巨大的痛苦)。虽然它并不完美(见下文):

# Download git and a musl compiler so that we don't depend on shitty glibc.

wget https://www.kernel.org/pub/software/scm/git/git-2.31.1.tar.gz
wget http://musl.cc/x86_64-linux-musl-cross.tgz

tar xvf git-2.31.1.tar.gz
tar xvf x86_64-linux-musl-cross.tgz

# Add the compiler to our path.
export PATH="$(pwd)/x86_64-linux-musl-cross/bin:$PATH"

cd git-2.31.1/

# Make output directory.
mkdir output

# Configure to use the musl compiler with static linking.
export CFLAGS="$CFLAGS -static"
./configure --build x86_64-linux-musl-cross --prefix="$(pwd)/output"

# Disable various dependencies to make it easier to compiler & link.
# Note that this means you can't use the https transport, you can still use
# ssh though. See https://github.com/git/git/blob/master/Makefile

make NO_OPENSSL=1 NO_CURL=1 NO_EXPAT=1 NO_GETTEXT=1 NO_PERL=1 NO_PYTHON=1 NO_TCLTK=1 -j8 install

不幸的是,Git 开始时是一堆 hacky shell 脚本——有些部分仍然是 shell 脚本!因此它编译成大量单独的二进制文件,而不是像您可能期望从一个精心设计的程序中得到的单个二进制文件,但它确实有效。你得到一个像这样的 output 目录:

$ tree
.
├── bin
│   ├── git
│   ├── git-cvsserver
│   ├── git-receive-pack
│   ├── git-shell
│   ├── git-upload-archive
│   └── git-upload-pack
├── libexec
│   └── git-core
│       ├── git
│       ├── git-add
│       ├── git-add--interactive
│       ├── git-am
│       ├── git-annotate
│       ├── git-apply
│       ├── git-archimport
│       ├── git-archive
│       ├── git-bisect
│       ├── git-bisect--helper
│       ├── git-blame
│       ├── git-branch
│       ├── git-bugreport
│       ├── git-bundle
│       ├── git-cat-file
│       ├── git-check-attr
│       ├── git-check-ignore
│       ├── git-check-mailmap
│       ├── git-checkout
│       ├── git-checkout-index
│       ├── git-check-ref-format
│       ├── git-cherry
│       ├── git-cherry-pick
│       ├── git-clean
│       ├── git-clone
│       ├── git-column
│       ├── git-commit
│       ├── git-commit-graph
│       ├── git-commit-tree
│       ├── git-config
│       ├── git-count-objects
│       ├── git-credential
│       ├── git-credential-cache
│       ├── git-credential-cache--daemon
│       ├── git-credential-store
│       ├── git-cvsexportcommit
│       ├── git-cvsimport
│       ├── git-cvsserver
│       ├── git-daemon
│       ├── git-describe
│       ├── git-diff
│       ├── git-diff-files
│       ├── git-diff-index
│       ├── git-difftool
│       ├── git-difftool--helper
│       ├── git-diff-tree
│       ├── git-env--helper
│       ├── git-fast-export
│       ├── git-fast-import
│       ├── git-fetch
│       ├── git-fetch-pack
│       ├── git-filter-branch
│       ├── git-fmt-merge-msg
│       ├── git-for-each-ref
│       ├── git-for-each-repo
│       ├── git-format-patch
│       ├── git-fsck
│       ├── git-fsck-objects
│       ├── git-gc
│       ├── git-get-tar-commit-id
│       ├── git-grep
│       ├── git-hash-object
│       ├── git-help
│       ├── git-http-backend
│       ├── git-imap-send
│       ├── git-index-pack
│       ├── git-init
│       ├── git-init-db
│       ├── git-instaweb
│       ├── git-interpret-trailers
│       ├── git-log
│       ├── git-ls-files
│       ├── git-ls-remote
│       ├── git-ls-tree
│       ├── git-mailinfo
│       ├── git-mailsplit
│       ├── git-maintenance
│       ├── git-merge
│       ├── git-merge-base
│       ├── git-merge-file
│       ├── git-merge-index
│       ├── git-merge-octopus
│       ├── git-merge-one-file
│       ├── git-merge-ours
│       ├── git-merge-recursive
│       ├── git-merge-resolve
│       ├── git-merge-subtree
│       ├── git-mergetool
│       ├── git-mergetool--lib
│       ├── git-merge-tree
│       ├── git-mktag
│       ├── git-mktree
│       ├── git-multi-pack-index
│       ├── git-mv
│       ├── git-name-rev
│       ├── git-notes
│       ├── git-p4
│       ├── git-pack-objects
│       ├── git-pack-redundant
│       ├── git-pack-refs
│       ├── git-patch-id
│       ├── git-prune
│       ├── git-prune-packed
│       ├── git-pull
│       ├── git-push
│       ├── git-quiltimport
│       ├── git-range-diff
│       ├── git-read-tree
│       ├── git-rebase
│       ├── git-rebase--preserve-merges
│       ├── git-receive-pack
│       ├── git-reflog
│       ├── git-remote
│       ├── git-remote-ext
│       ├── git-remote-fd
│       ├── git-repack
│       ├── git-replace
│       ├── git-request-pull
│       ├── git-rerere
│       ├── git-reset
│       ├── git-restore
│       ├── git-revert
│       ├── git-rev-list
│       ├── git-rev-parse
│       ├── git-rm
│       ├── git-send-email
│       ├── git-send-pack
│       ├── git-shell
│       ├── git-sh-i18n
│       ├── git-sh-i18n--envsubst
│       ├── git-shortlog
│       ├── git-show
│       ├── git-show-branch
│       ├── git-show-index
│       ├── git-show-ref
│       ├── git-sh-setup
│       ├── git-sparse-checkout
│       ├── git-stage
│       ├── git-stash
│       ├── git-status
│       ├── git-stripspace
│       ├── git-submodule
│       ├── git-submodule--helper
│       ├── git-svn
│       ├── git-switch
│       ├── git-symbolic-ref
│       ├── git-tag
│       ├── git-unpack-file
│       ├── git-unpack-objects
│       ├── git-update-index
│       ├── git-update-ref
│       ├── git-update-server-info
│       ├── git-upload-archive
│       ├── git-upload-pack
│       ├── git-var
│       ├── git-verify-commit
│       ├── git-verify-pack
│       ├── git-verify-tag
│       ├── git-web--browse
│       ├── git-whatchanged
│       ├── git-worktree
│       ├── git-write-tree
│       └── mergetools
│           ├── araxis
│           ├── bc
│           ├── codecompare
│           ├── deltawalker
│           ├── diffmerge
│           ├── diffuse
│           ├── ecmerge
│           ├── emerge
│           ├── examdiff
│           ├── guiffy
│           ├── gvimdiff
│           ├── kdiff3
│           ├── kompare
│           ├── meld
│           ├── nvimdiff
│           ├── opendiff
│           ├── p4merge
│           ├── smerge
│           ├── tkdiff
│           ├── tortoisemerge
│           ├── vimdiff
│           ├── winmerge
│           └── xxdiff
└── share
    └── git-core
        └── templates
            ├── branches
            ├── description
            ├── hooks
            │   ├── applypatch-msg.sample
            │   ├── commit-msg.sample
            │   ├── fsmonitor-watchman.sample
            │   ├── post-update.sample
            │   ├── pre-applypatch.sample
            │   ├── pre-commit.sample
            │   ├── pre-merge-commit.sample
            │   ├── prepare-commit-msg.sample
            │   ├── pre-push.sample
            │   ├── pre-rebase.sample
            │   ├── pre-receive.sample
            │   ├── push-to-checkout.sample
            │   └── update.sample
            └── info
                └── exclude

10 directories, 206 files

bin 目录添加到您的 PATH 中,您就可以开始了!有两个注意事项:

  1. 我们禁用了 OpenSSL 和 Curl 等,这意味着您不能使用 https:// URL - 只能使用 ssh://

  2. 如果您将它移动到任何地方,您会收到有关缺少模板的警告。

这是因为它使用了 autotools(另一个大 hack)而 autotools 几乎拒绝承认人们可能需要可移植程序,所以你必须将它安装到编译时固定的绝对 路径。 Git 使用它来定位 templates 目录,因此如果您将 output 目录移动到其他任何地方,您就会开始收到如下警告:

warning: templates not found in /home/tim/local/git-2.31.1/output/share/git-core/templates

但是由于某些原因,所有 git 命令本身都可以正常工作 - 您可以执行 git initgit log 等等,它即使您移动它,也会以某种方式找到 libexec/git_core 目录。

https://stackoverflow.com/questions/13570524/

相关文章:

mysql - 我可以杀死 "repair by keycache"吗?

sql-server - 读取 DONE_IN_PROC

debugging - Nemiver - 无法直接标准输入

css - 溢出滚动不滚动?

javascript - path.node().getTotalLength() 挂起浏览器

python - 如何通过终端获取mac os的语言

css - 向剪切框添加投影

python - Arduino 和 PyBluez 之间的蓝牙通信

batch-file - 如何保存包含俄语或中文字符的文件的目录列表

html5-video - 嵌入/使用 mediaelement.js 的正确方法