如何仅使用 git log 显示更改的文件名?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14207414/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to show changed file name only with git log?
提问by fannheyward
Is it able to show changed file nameonly with git log
?
它是能够显示更改后的文件名只能用git log
?
回答by fannheyward
Thanks for your answers, @mvp, @xero, I get what I want base on both of your answers.
感谢您的回答,@mvp,@xero,根据您的两个答案,我得到了我想要的。
git log --name-only
or
或者
git log --name-only --oneline
for short.
简称。
回答by xero
i guess your could use the --name-only
flag. something like:
我想你可以使用--name-only
标志。就像是:
git log 73167b96 --pretty="format:" --name-only
git log 73167b96 --pretty="format:" --name-only
i personally use git show
for viewing files changed in a commit
我个人git show
用于查看提交中更改的文件
git show --pretty="format:" --name-only 73167b96
git show --pretty="format:" --name-only 73167b96
(73167b96 could be any commit/tag name)
(73167b96 可以是任何提交/标签名称)
回答by gMale
I stumbled in here looking for a similar answer without the "git log" restriction. The answers here didn't give me what I needed but this did so I'll add it in case others find it useful:
我偶然在这里寻找没有“git log”限制的类似答案。这里的答案没有给我我需要的东西,但这样做了,所以我会添加它,以防其他人觉得它有用:
git diff --name-only
You can also couple this with standard commit pointers to see what has changed since a particular commit:
您还可以将其与标准提交指针结合使用,以查看自特定提交以来发生了什么变化:
git diff --name-only HEAD~3
git diff --name-only develop
git diff --name-only 5890e37..ebbf4c0
This succinctly provides file names onlywhich is great for scripting. For example:
这仅提供了非常适合脚本编写的文件名。例如:
git diff --name-only develop | while read changed_file; do echo "This changed from the develop version: $changed_file"; done
#OR
git diff --name-only develop | xargs tar cvf changes.tar
回答by mvp
This gives almost what you need:
这几乎提供了您所需要的:
git log --stat --oneline
Commit id + short one line still remains, followed by list of changed files by that commit.
提交 id + 短一行仍然保留,后跟该提交更改的文件列表。
回答by Alfergon
Now I use the following to get the list of changed files my current branch has, comparing it to master (the compare-to branch is easily changed):
现在我使用以下命令获取我当前分支的已更改文件列表,并将其与 master 进行比较(比较分支很容易更改):
git log --oneline --pretty="format:" --name-only master.. | awk 'NF' | sort -u
Before, I used to rely on this:
之前,我曾经依赖于这个:
git log --name-status <branch>..<branch> | grep -E '^[A-Z]\b' | sort -k 2,2 -u
which outputs a list of files only and their state (added, modified, deleted):
它只输出文件列表及其状态(添加、修改、删除):
A foo/bar/xyz/foo.txt
M foo/bor/bar.txt
...
The -k2,2
option for sort, makes it sort by file path instead of the type of change (A, M, D,).
所述-k2,2
用于排序选项,使得排序文件路径,而不是改变的类型(A,M,d,)。
回答by jmarceli
If you need justfile names like:
如果您只需要文件名,例如:
dir/subdir/file1.txt
dir/subdir2/file2.sql
dir2/subdir3/file6.php
(which I use as a source for tarcommand) you will also need to filter out commit messages.
(我将其用作tar命令的来源)您还需要过滤掉提交消息。
In order to do this I use following command:
为了做到这一点,我使用以下命令:
git log --name-only --oneline | grep -v '.{7} '
git log --name-only --oneline | grep -v '.{7} '
Grep command excludes (-v
param) every line which starts with seven symbols (which is the length of my git hash for git log
command) followed by space. So it filters out every git hash message
line and leave only lines with file names.
Grep 命令排除 ( -v
param) 以七个符号开头的每一行(这是git log
命令的git 哈希的长度),后跟空格。所以它过滤掉每一个 githash message
行,只留下带有文件名的行。
One useful improvement is to append uniq
to remove duplicate lines so it will looks as follow:
一项有用的改进是追加uniq
删除重复行,使其看起来如下:
git log --name-only --oneline | grep -v '.{7} ' | uniq
git log --name-only --oneline | grep -v '.{7} ' | uniq