我如何识别在git commit中添加或删除的文件/目录? [英] how do i identify files/directories that were added or removed in a git commit?
问题描述
我需要编写一个脚本,用于逐步跟踪从git仓库中添加和删除的文件和目录。
我曾尝试使用:
git log -n1 --pretty =format: - 仅限名称
但是,这只会告诉我哪些文件已经提交。它不指定它是否被添加或删除。
有什么想法?
您正在寻找的选项是 - name-status
。像 - 仅限名称
它实际上是一个git-diff选项; git-log接受这些以确定它将如何显示补丁。
git log -n 1 --pretty = oneline - 名称状态
或等效(减去日志标题):
git diff --name-status HEAD ^ HEAD
正如isbadawi指出的那样,你也可以使用git-whatchanged。这是一个具有特定差异输出的git-log:
git whatchanged -n 1
不过,您可能更喜欢 - name-status
版本,因为它不会显示所有blob哈希,只是人类可读的状态。
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?
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.
这篇关于我如何识别在git commit中添加或删除的文件/目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!