Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git - list of all changed but not deleted files in a commit

Tags:

git

I am investigating git repositories. I want to get the list of changed files in each commit.

So, what I did is I visited each commit through the command

git reset --hard <commitId>

Then, I used

git show --pretty="format:" --name-only #{commitId}

The problem with this one is that it gives the deleted files in that commitId which I don't want. I tried also:

git ls-files 

it doesn't return deleted files, however, it returns a list of all existing files that are new or were created in previous commit.

Example:

>commit 1
add "file1"
add "file2"

>commit 2
change "file1"

>commit 3
add "file3"
delete "file2"

so in this case, I will visit each commit. And, if I am in commit 1, I want to get a list of "file1" and "file2". If I am in commit 2, I will get "file1", and "file3" if I am in commit 3.

Any thought?

like image 643
Arwa Avatar asked Jun 18 '15 01:06

Arwa


1 Answers

You don't have to reset HEAD to an earlier commit in order to do this, i.e. you don't have to lose your local changes, git diff allows you to compare between any two commits as long as you privide the commit hashes. In your case you can do:

git diff {COMMIT_1_HASH} {COMMIT_2_HASH} --name-only --diff-filter=AM

This can be used to see the files added and changed between any number of commits.

If you want to get the files added and modified for only one commit then just use the commit hash that comes right after the one you are trying to look at.

like image 198
Mauricio Trajano Avatar answered Sep 28 '22 10:09

Mauricio Trajano