Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use full paths in git?

This command works fine:

git diff relative/path/to/file.ext

But if I use the full path, git says that path "is outside repository":

git diff /full/path/then/relative/path/to/file.ext

I suppose git does not find a .git directory in /full, so that's why it fails.

But how do I make git understand full paths, like subversion does?

Update: git version 1.7.0.5

Update: These files are always inside my repository, and my current directory is also inside my repository! It still gives that error.

like image 539
Will Sheppard Avatar asked Dec 19 '11 11:12

Will Sheppard


People also ask

What is a full file path?

A full path is also referred to as the file path or the absolute path and refers to the location of your web site files on the server, relative to the server's file system structure.

What is Git status porcelain?

Porcelain Format Version 1 Version 1 porcelain format is similar to the short format, but is guaranteed not to change in a backwards-incompatible way between Git versions or based on user configuration. This makes it ideal for parsing by scripts.

What does add command do in Git?

The git add command adds a change in the working directory to the staging area. It tells Git that you want to include updates to a particular file in the next commit.


1 Answers

Which version of git are you using? It should work regardless of the format of the path, i.e.

cd git
git diff -- git.c
git diff -- ~/git/git.c

But you have to be inside the git repository for this to work! If you absolutely need the git command to be executed from outside the repository, use the --work-tree and --git-dir switches:

git --work-tree=~/git --git-dir=~/git/.git diff -- git.c
git --work-tree=~/git --git-dir=~/git/.git diff -- ~/git/git.c
like image 100
knittl Avatar answered Oct 06 '22 03:10

knittl