git/list[1] front-page[2] threads[3] people[4] search[5] about
 

git ls-files -X option is relative to repo root

From
DFDaniel Finnie <dan@danfinnie.com>
Date
Feb 13, 2015, 19:23 UTC
Message-ID
<CAG4vEKM-2sy0z3=YLS+rgH99w6ukdcNBode9CAh4C4t9eSa02A@mail.gmail.com>

I encountered some unexpected behavior with Git today and was hoping to either a) clear up my misconception or b) make a bug report.

My question deals with the --exclude-from option to git-ls-files. It appears that paths passed to this option are relative to the root of the repository, not your current working directory. I would have expected the opposite, that the paths are relative to the working directory. I would expect to put a colon at the beginning of the path to make it relative to the repository root. Here's an example:

$ tree -a -I .git
.
├── .gitignore
└── example_dir
    ├── .gitignore
    └── example_file

# (all of these files are checked in, including example_file which is also in .gitignore)

$ cat .gitignore # empty gitignore

$ cat example_dir/.gitignore example_file

$ (cd example_dir && git ls-files --ignore --exclude-from=.gitignore) # No output because this references the git ignore at the project root, not example_dir. I expected this to output "example_file".

$ (cd example_dir && git ls-files --ignore --exclude-from=example_dir/.gitignore) example_file # works for the reason above, but I expected this to break because example_dir/example_dir/.gitignore is not a file

So, what do you think? Am I missing a git/*nix convention explaining options would be specified relative to the repository root? Or is this a git bug?

Thanks for your time, Dan Finnie

Next: Junio C Hamano
Message 1 of 5 in “git ls-files -X option is relative to repo root”
  1. Daniel FinnieFeb 13, 2015
  2. Junio C HamanoFeb 13, 2015
  3. Junio C HamanoFeb 13, 2015
  4. Daniel FinnieFeb 13, 2015
  5. Junio C HamanoFeb 13, 2015

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.