例:
$ cd lib
$ git absolute-path test.c # how to do this?
lib/test.c
Run Code Online (Sandbox Code Playgroud)
Jo *_*iss 24
至少git 1.6.0,使用 ls-files:
$ cd lib
$ git ls-files --full-name test.c
lib/test.c
Run Code Online (Sandbox Code Playgroud)
使用 git ls-tree:
$ cd lib
$ git ls-tree --full-name --name-only HEAD test.c
lib/test.c
Run Code Online (Sandbox Code Playgroud)
这仅适用于已提交到repo的文件,但它总比没有好.
无论"test.c"当前是否存在,将以下内容粘贴到bash终端都可以.您可以将git-absolute-path函数复制到.bashrc文件中以方便使用.
git-absolute-path () {
fullpath=$([[ $1 = /* ]] && echo "$1" || echo "$PWD/${1#./}")
gitroot="$(git rev-parse --show-toplevel)" || return 1
[[ "$fullpath" =~ "$gitroot" ]] && echo "${fullpath/$gitroot\//}"
}
git-absolute-path test.c
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
13334 次 |
| 最近记录: |