Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get ONLY filename with path using git log?

I used almost all git log commands yet i haven't found a best way to do this. I need only this - get only file name with path nothing else

/path/filename.txt
/path/anotherfile.ext
...
...

My input is date FROM and TO to the git log command. Either git log gives developer-name or date or commit-number or something that i don't want with file names. How to get ONLY the file name with full path?

like image 718
Murali Uppangala Avatar asked Oct 12 '15 12:10

Murali Uppangala


People also ask

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

Usage. 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.

How do I view files in git log?

Find what file changed in a commit To find out which files changed in a given commit, use the git log --raw command. It's the fastest and simplest way to get insight into which files a commit affects.

What is git diff -- name only?

To explain further: The -z to with git diff --name-only means to output the list of files separated with NUL bytes instead of newlines, just in case your filenames have unusual characters in them. The -0 to xargs says to interpret standard input as a NUL-separated list of parameters.

What is git Whatchanged?

The whatchanged command is essentially the same as git-log[1] but defaults to show the raw format diff output and to skip merges. The command is kept primarily for historical reasons; fingers of many people who learned Git long before git log was invented by reading Linux kernel mailing list are trained to type it.


2 Answers

Use --name-only and remove the message with an empty format

git log --name-only --format=""

Just use all other git log options as usual. E.g.

git log --name-only --format="" -n 2 master

Optionally sort and remove dupplicates

git log --name-only --format="" | sort | uniq
like image 152
René Link Avatar answered Oct 31 '22 11:10

René Link


Use the --since and --until options to select the time range and then you can use UNIX pipes to grep, sort and collect the uniqe paths:

git log --name-status --since='..' --until='..' | grep -E '^[A-Z]\b' | sort | uniq | sed -e 's/^\w\t*\ *//'

Example:

git log --name-status --since='1 January 2015' --until='2 January 2015' | grep -E '^[A-Z]\b' | sort | uniq | sed -e 's/^\w\t*\ *//'

For more detailed git log outputs see How to have git log show filenames like svn log -v


If you have two commit hashes, you can also use git diff and --name-only instead, as the other answer mentions:

git diff hash1..hash2 --name-only
like image 35
Ionică Bizău Avatar answered Oct 31 '22 09:10

Ionică Bizău