如何从特定目录而不是仓库的根目录执行git别名

编程入门 行业动态 更新时间:2024-10-27 01:27:26
本文介绍了如何从特定目录而不是仓库的根目录执行git别名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

Git似乎从仓库的根目录开始执行所有别名.您可以使用以下别名查看此信息:

Git seems to execute all the aliases from the root of the repo. You can see this by using the following alias:

test = !pwd

甚至

test2 = "!f() { pwd ;}; f"

这两者都将显示存储库根目录,而不是您所在的子目录.

which will both display the directory of the root of the repo, not the subdirectory that you are in.

如何创建从您所在目录而不是根目录执行的别名?

How can I make an alias that executes from the directory that you are in, not the root?

推荐答案

您可以使用变量$GIT_PREFIX.例如:

You can use the variable $GIT_PREFIX. For example:

test = !echo $GIT_PREFIX

或更有效的用例:

cat-from = "!f() { git show $1:\"$GIT_PREFIX$2\" ;}; f"

可以用来从特定分支中收集文件,而无需检出它:git cat-from master foo.txt

which can be used to cat a file from a particular branch without checking it out: git cat-from master foo.txt

我在以下源代码中找到了它: github/git/git/blob/35f6318d44379452d8d33e880d8df0267b4a0cd0/t/t1020-subdirectory.sh#L131

I found this by looking in the source code here: github/git/git/blob/35f6318d44379452d8d33e880d8df0267b4a0cd0/t/t1020-subdirectory.sh#L131

如果可以找到记录在哪里,请添加编辑/评论/答案.

Please add an edit/comment/answer if you can find where this is documented.

更多推荐

如何从特定目录而不是仓库的根目录执行git别名

本文发布于:2023-08-02 11:51:04,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1277573.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:根目录   别名   仓库   而不是   目录

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!