Git - a list of all modified but not deleted files in the commit

I am studying git repositories. I want to get a list of modified files in each commit.

So what I did, I visited every commit with the command

git reset --hard <commitId> 

Then i used

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

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

 git ls-files 

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

Example:

 >commit 1 add "file1" add "file2" >commit 2 change "file1" >commit 3 add "file3" delete "file2" 

therefore, in this case I will visit every 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?

+6
source share
2 answers

Try using this command:

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

This is what you mentioned in your original problem by adding the --diff-filter flag to limit only files added ( A ) or modified ( M ). For a complete list of file types that you can limit, see the documentation for git show .

As @MauricioTrajano pointed out in his answer, you don't need to reset comment to explore it with git show . All you need to know is the SHA-1 hash of the commit, which you can find just by using git log in the corresponding branch.

+5
source

For this you do not need to reset HEAD for an earlier commit, i.e. you don’t need to lose local changes, git diff allows you to compare between any two commits while you privatize hashes. In your case, you can:

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

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

If you want files to be added and changed for only one commit, just use the commit hash code that appears immediately after the one you are trying to view.

+2
source

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


All Articles