190

Is it able to show changed file name only with git log?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
fannheyward
  • 18,599
  • 12
  • 71
  • 109
  • Somewhat related: [Bash function to find all Git commits in which a file (whose name matches a regex) has *changed*](http://stackoverflow.com/questions/28119379/bash-function-to-find-all-git-commits-in-which-a-file-whose-name-matches-a-rege/28120305) – aliteralmind Jan 24 '15 at 21:22

6 Answers6

274

I use

git log --name-only 

or

git log --name-only --oneline

for short.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
fannheyward
  • 18,599
  • 12
  • 71
  • 109
95

I guess you could use the --name-only flag. Something like:

git log 73167b96 --pretty="format:" --name-only

I personally use git show for viewing files changed in a commit:

git show --pretty="format:" --name-only 73167b96

(73167b96 could be any commit/tag name)

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
xero
  • 4,077
  • 22
  • 39
  • 7
    this solution is pretty nice to ONLY have the list of files without author, date or commit message info – Labynocle Mar 26 '14 at 14:59
  • 1
    That's pretty much exactly what I was looking for - but it does include the commit message for me - as I wanted to pipe the output, that wasn't optimal. – bytepusher Jan 01 '20 at 10:51
  • super, thanks a lot! All i now need to open all changed files in last commit is ```alias gshsubl='git show --name-only --pretty="format:" --name-only|xargs subl' ``` – lain0 Apr 29 '22 at 12:37
44

I stumbled in here looking for a similar answer without the "git log" restriction. The answers here didn't give me what I needed but this did so I'll add it in case others find it useful:

git diff --name-only

You can also couple this with standard commit pointers to see what has changed since a particular commit:

git diff --name-only HEAD~3
git diff --name-only develop
git diff --name-only 5890e37..ebbf4c0

This succinctly provides file names only which is great for scripting. For example:

git diff --name-only develop | while read changed_file; do echo "This changed from the develop version: $changed_file"; done

#OR

git diff --name-only develop | xargs tar cvf changes.tar
gMale
  • 17,147
  • 17
  • 91
  • 116
37

This gives almost what you need:

git log --stat --oneline

The commit ID and a short one line still remains, followed by a list of changed files by that commit.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
mvp
  • 111,019
  • 13
  • 122
  • 148
24

Now I use the following to get the list of changed files my current branch has, comparing it to master (the compare-to branch is easily changed):

git log --oneline --pretty="format:" --name-only master.. | awk 'NF' | sort -u

Before, I used to rely on this:

git log --name-status <branch>..<branch> | grep -E '^[A-Z]\b' | sort -k 2,2 -u

which outputs a list of files only and their state (added, modified, deleted):

A   foo/bar/xyz/foo.txt
M   foo/bor/bar.txt
...

The -k2,2 option for sort, makes it sort by file path instead of the type of change (A, M, D,).

Alfergon
  • 5,463
  • 6
  • 36
  • 56
  • 4
    This is literally the only answer that actually provides the answer to the question of "file name only". – DrStrangepork Jun 13 '17 at 19:43
  • Short addition: this command will also shows that have been added and subsequently renamed or removed in the same branch. These files may no longer exist. – Aron Rotteveel May 25 '18 at 10:08
12

If you need just file names, like:

dir/subdir/file1.txt
dir/subdir2/file2.sql
dir2/subdir3/file6.php

(which I use as a source for tar command), you will also need to filter out commit messages.

In order to do this, I use the following command:

git log --name-only --oneline | grep -v '.{7} '

The grep command excludes (the -v parameter) every line which starts with seven symbols (which is the length of my Git hash for the git log command) followed by space. So it filters out every Git hash message line and leave only lines with file names.

One useful improvement is to append uniq to remove duplicate lines, so it will look as follows:

git log --name-only --oneline | grep -v '.{7} ' | uniq
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
jmarceli
  • 19,102
  • 6
  • 69
  • 67
  • 4
    In OSX bash shell, its necessary to put backslashes before the brackets. I also added the line start matching and space matcher. "git show --name-only --oneline | grep -v '^.\{7\}\s'" – Geuis Jun 12 '14 at 00:31