How to use full paths in git?

This command works just fine:

git diff relative/path/to/file.ext 

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

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

I believe git does not find the .git directory in / full, so why it does not work.

But how do I make git understand the full paths, such as subversion?

Update: git version 1.7.0.5

Update: these files are always inside my repository, and my current directory is also inside my repository! He still gives this error.

+6
source share
2 answers

What 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 in the git repository for this to work! If you absolutely need a git command that needs to be run from outside the repository, use the --work-tree and --git-dir :

 git --work-tree=~/git --git-dir=~/git/.git diff -- git.c git --work-tree=~/git --git-dir=~/git/.git diff -- ~/git/git.c 
+13
source

If you want to split the file outside the git repository, you should use a diff tool like opendiff and compare the file with the repo with another file outside the repository.

You cannot compare external files because git does not "think" in files.

0
source

Source: https://habr.com/ru/post/904072/


All Articles