问题描述
总结:目前通过git别名运行的命令的工作目录是错误的。
最简单的演示方法是使用git别名: p>
[alias]
pwd =!pwd
所以 git pwd
只是运行bash命令 pwd
。人们会认为这两个命令的输出是一样的。现在,我们来试试一下这个例子:
$ cd〜
$ pwd&& git pwd
/ home / limpchimp
/ home / limpchimp#great!
$ mkdir foo&& cd foo&&& git init
/home/limpchimp/foo/.git/
$ pwd&&&&& git pwd
/ home / limpchimp / foo
/ home / limpchimp / foo#great!
$ mkdir bar&& cd bar
$ pwd&&& git pwd
/ home / limpchimp / foo / bar
/ home / limpchimp / foo#uuhhhhhhhhh ...?
似乎git正在将当前工作目录更改为第一个具有 .git
文件夹(如果存在)。这是非常有问题的;它正在拧紧我写的某些脚本,这些脚本旨在在特定目录中运行,并使我无法使用某些东西作为git别名。有没有解决的办法?如何修复?
这是根据设计在文档中明确指定的,如果需要,还有解决方法。 p>
Summary: the current working directory of commands run through git aliases is wrong.
The easiest way to demonstrate this is to have a git alias like so:
[alias]
pwd = !pwd
So git pwd
is just running the bash command pwd
. One would think that the two commands' outputs would be the same. Now, let's try this out a few times:
$ cd ~
$ pwd && git pwd
/home/limpchimp
/home/limpchimp # great!
$ mkdir foo && cd foo && git init
Initialized empty Git repository in /home/limpchimp/foo/.git/
$ pwd && git pwd
/home/limpchimp/foo
/home/limpchimp/foo # great!
$ mkdir bar && cd bar
$ pwd && git pwd
/home/limpchimp/foo/bar
/home/limpchimp/foo # uuhhhhhhhh...?
It seems that git is changing the current working directory to be the first parent directory that has a .git
folder (if one exists). This is very problematic; it's screwing up certain scripts that I've written, which are meant to operate in a specific directory, and making me unable to use certain things as git aliases. Is there a way around this? How can I fix it?
This is clearly specified in the documentation as by design along with a workaround if needed.
这篇关于git别名在错误的目录下运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!