Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the path of a file relative to the Git repository root?

Tags:

git

path

Example:

$ cd lib $ git absolute-path test.c # how to do this? lib/test.c 
like image 378
Jo Liss Avatar asked Jun 05 '13 23:06

Jo Liss


People also ask

How do I find the path of a file in git?

While browsing your Git repository, start typing in the path control box to search for the file or folder you are looking for. The interface lists the results starting from your current folder followed by matching items from across the repo.


1 Answers

As of at least git 1.6.0, use ls-files:

$ cd lib $ git ls-files --full-name test.c lib/test.c 

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.

like image 147
Jo Liss Avatar answered Sep 29 '22 02:09

Jo Liss