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

北城以北 提交于 2019-12-06 17:04:08

问题


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?


回答1:


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.




回答2:


git whatchanged



来源:https://stackoverflow.com/questions/2557564/how-do-i-identify-files-directories-that-were-added-or-removed-in-a-git-commit

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!