Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

(git) diff output relative path?

I need to get some diffs in my repo that are not relative to the base of the repo, but instead relative to a given base or given path.

By default I get:

git diff diff --git a/path/to/file b/path/to/file index 0cc125e..9bf911e 100644 --- a/path/to/file +++ b/path/to/file 

But what I want is something like:

git diff --prefix=/new/path/to diff --git a/new/path/to/file b/new/path/to/file index 0cc125e..9bf911e 100644 --- a/new/path/to/file +++ b/new/path/to/file 

I have looked over the --relative option (not what I am looking for), the --src/dst-prefix (these can only change the "a" or "b" parts. Am I missing something basic?

like image 440
user318904 Avatar asked Apr 10 '14 22:04

user318904


People also ask

How do I see git diff?

You can run the below commands to compare the changes for specific file: git diff HEAD <file_name> git diff <file_name>

How does git diff work internally?

Diffing is a function that takes two input data sets and outputs the changes between them. git diff is a multi-use Git command that when executed runs a diff function on Git data sources. These data sources can be commits, branches, files and more.

What is git diff cached?

explainshell.com - git diff --cached. Show changes between the working tree and the index or a tree, changes between the index and a tree, changes between two trees, or changes between two files on disk.

What does git diff head do?

The git diff HEAD [filename] command allows you to compare the file version in your working directory with the file version last committed in your remote repository. The HEAD in the git command refers to the remote repository.


1 Answers

git diff prints paths (of changed files) from the root of the repo - no matter where you are when executing the command.

git diff --relative will print paths from the dir you are in.

So if you need paths not starting from the repo-root move down (cd) to the directory (within your repo tree) where you with your paths to start from.

like image 68
luisa rosi Avatar answered Sep 16 '22 19:09

luisa rosi