windows 移动可移植 git 配置的目录
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3169355/
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
Moving directories for portable git configuration
提问by Mottie
I have installed the portable git version on my flash drive, but I don't want my repository to be in the same directory as the program. I can get to the directory using:
我已经在我的闪存驱动器上安装了便携式 git 版本,但我不希望我的存储库与程序位于同一目录中。我可以使用以下方法进入目录:
$ git -- git-dir=../Gits --work-tree=..Gits
But I don't want to enter that every time. So I found in this articleon the gitconfig
file. But it only shows how to set the core.worktree
但我不想每次都输入。所以,我在发现这篇文章的gitconfig
文件。但它只显示如何设置core.worktree
core.worktree
Set the path to the root of the work tree. This can be overridden by the GIT_WORK_TREE environment variable and the --work-tree command line option. It can be an absolute path or a relative path to the .git directory, either specified by --git-dir or GIT_DIR, or automatically discovered. If --git-dir or GIT_DIR are specified but none of --work-tree, GIT_WORK_TREE and core.worktree is specified, the current working directory is regarded as the root of the work tree.
Note that this variable is honored even when set in a configuration file in a ".git" subdirectory of a directory, and its value differs from the latter directory (e.g. "/path/to/.git/config" has core.worktree set to "/different/path"), which is most likely a misconfiguration. Running git commands in "/path/to" directory will still use "/different/path" as the root of the work tree and can cause great confusion to the users.
核心工作树
将路径设置为工作树的根。这可以被 GIT_WORK_TREE 环境变量和 --work-tree 命令行选项覆盖。它可以是 .git 目录的绝对路径或相对路径,可以由 --git-dir 或 GIT_DIR 指定,也可以自动发现。如果指定了--git-dir 或 GIT_DIR,但未指定--work-tree、GIT_WORK_TREE 和 core.worktree,则将当前工作目录视为工作树的根。
请注意,即使在目录的“.git”子目录中的配置文件中设置此变量时也会受到尊重,并且其值与后一个目录不同(例如“/path/to/.git/config”设置了 core.worktree到“/不同/路径”),这很可能是配置错误。在“/path/to”目录下运行git命令仍然会使用“/different/path”作为工作树的根目录,这会给用户带来很大的困惑。
I have tried these settings to no avail.
我已经尝试过这些设置无济于事。
[core]
worktree = ../Gits
gitdir = ../Gits
Does anyone know a way to set the git-dir
and work-tree
directories for PortableGit-1.7.0.2-preview20100309.7zfor Windows so I don't have to type that in all the time?
有谁知道为 Windows 的PortableGit-1.7.0.2-preview20100309.7z设置git-dir
和work-tree
目录的方法,所以我不必一直输入?
Also is there a way to add the passphrase so I don't have to type that in either? I saw these instructions, but the portable version apparently doesn't have a ~/.profile
or ~/.bashrc
file.
还有没有办法添加密码,这样我就不必输入密码?我看到了这些说明,但便携式版本显然没有~/.profile
or~/.bashrc
文件。
回答by VonC
Why would any git repo in the same directory than your portable installation?
为什么任何 git repo 都在与便携式安装相同的目录中?
As long as your %PATH%
reference your portable Git/cmd
directory, you can just type 'git whatever
' in your Git repo anywhere, and the working directory and git directory will be at their default places.
只要你%PATH%
引用你的可移植Git/cmd
目录,你就可以git whatever
在你的 Git 存储库中的任何地方输入 ' ',工作目录和 git 目录将在它们的默认位置。
And any Git version has access to ~/.profile
or ~/.bashrc
: open a Git bashrc
, and type cd
, then pwd
: the path displayed is your '~
'.
Then, if you have no .profile
or .bashrc
yet, create one, put it it a simple echo (echo .profile
in the .profile
file, 'echo .bashrc
' in the .bashrc
), open another Git bashrc and check if your .profile
/.bashrc
are activated.
并且任何 Git 版本都可以访问~/.profile
或~/.bashrc
:打开一个Git bashrc
,然后键入cd
,然后pwd
: 显示的路径是您的“ ~
”。
然后,如果你没有.profile
或.bashrc
还没有,创建一个,把它放在一个简单的回声中(echo .profile
在.profile
文件中,' echo .bashrc
' .bashrc
),打开另一个 Git bashrc 并检查你的.profile
/.bashrc
是否被激活。