Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how do i identify files/directories that were added or removed in a git commit?

Tags:

I need to write a script that incrementally keeps track of files and directories added and removed from a git repo.

I have tried to use:

git log -n1 --pretty="format:" --name-only 

But that only tells me which files were committed. It does not specify if it was added or removed.

Any ideas?

like image 825
pocketfullofcheese Avatar asked Apr 01 '10 01:04

pocketfullofcheese


People also ask

How do you see what files were changed in a commit?

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.

How do you find who deleted files in git?

Listing all the deleted files in all of git history can be done by combining git log with --diff-filter .


2 Answers

The option you're looking for is --name-status. Like --name-only it's actually a git-diff option; git-log accepts those to determine how it'll display patches.

git log -n 1 --pretty=oneline --name-status 

Or equivalently (minus the log header):

git diff --name-status HEAD^ HEAD 

As isbadawi points out, you can also use git-whatchanged. This is pretty much git-log with a specific diff output:

git whatchanged -n 1 

You might like the --name-status version better, though, since it doesn't show all the blob hashes, just the human-readable statuses.

like image 119
Cascabel Avatar answered Sep 19 '22 04:09

Cascabel


git whatchanged

like image 23
Ismail Badawi Avatar answered Sep 19 '22 04:09

Ismail Badawi