如何获取相对于Git存储库根目录的文件路径? [英] How to get the path of a file relative to the Git repository root?
本文介绍了如何获取相对于Git存储库根目录的文件路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
示例:
$ cd lib
$ git absolute-path test.c # how to do this?
lib/test.c
推荐答案
从git 1.6.0起,至少使用 ls-files
:
As of at least git 1.6.0, use ls-files
:
$ cd lib
$ git ls-files --full-name test.c
lib/test.c
对于较旧的git,请使用 git ls-tree
:>
For older git, use git ls-tree
:
$ cd lib
$ git ls-tree --full-name --name-only HEAD test.c
lib/test.c
这仅适用于已提交到存储库中的文件,但总比没有好.
This only works for files that have been committed into the repo, but it's better than nothing.
这篇关于如何获取相对于Git存储库根目录的文件路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文