git:显示两次提交之间更改的所有文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3144647/
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
git: show all files changed between two commits
提问by Andrew
A riff on git: show all changed files between two commits: I want a listing of all files that have been changed between two commits, even if they are now the same (ie, changed and then changed back).
git上的即兴表演:显示两次提交之间所有更改的文件:我想要列出两次提交之间已更改的所有文件,即使它们现在是相同的(即,更改后又更改回来)。
回答by igorw
This is the best I could come up with:
这是我能想到的最好的:
git log --name-only --pretty=oneline --full-index HEAD^^..HEAD | grep -vE '^[0-9a-f]{40} ' | sort | uniq
Replace HEAD^^ and HEAD with the commits you want to compare.
将 HEAD^^ 和 HEAD 替换为您要比较的提交。
My attempt uses git log
with --name-only
to list all files of each commit between the specified ones. --pretty=oneline
makes the part above the file listing consist only of the commit SHA and message title. --full-index
makes the SHA be the full 40 characters. grep
filters out anything looking like a SHA followed by a space. Unless you have files beginning with a SHA followed by a space, the result should be accurate.
我尝试使用git log
with--name-only
列出指定文件之间每个提交的所有文件。--pretty=oneline
使文件列表上方的部分仅包含提交 SHA 和消息标题。--full-index
使 SHA 成为完整的 40 个字符。grep
过滤掉任何看起来像 SHA 后跟一个空格的东西。除非您的文件以 SHA 开头,后跟一个空格,否则结果应该是准确的。
回答by brycemcd
I think this command is your answer:
我认为这个命令是你的答案:
git diff --stat abc123 xyz123 # where abc123 and xyz123 are SHA1 hashes of commit objects
Straight from the git community book:
直接来自git 社区书:
If you don't want to see the whole patch, you can add the '--stat' option, which will limit the output to the files that have changed along with a little text graph depicting how many lines changed in each file.
如果您不想看到整个补丁,可以添加“--stat”选项,它将输出限制为已更改的文件以及描述每个文件中更改的行数的小文本图。
回答by Lloyd Rochester
If just want to see the file names where commit b
is chronologically after a
:
如果只想查看提交b
按时间顺序排列的文件名a
:
git diff <a commit sha1>...<b commit sha2> --name-only # b is after a in time
If you want to see all the file names and what was changed from commit a to commit b then drop the last argument.
如果您想查看所有文件名以及从 commit a 到 commit b 的更改,请删除最后一个参数。
git diff <a commit sha1>...<b commit sha2> # shows file names and what changed in each file
An example of <commit sha1>
are the commit id's like 675ee6860d2c273bcc6c6a0536634a107e2a3d9f
. Generally the first 8-10 digits will work on most projects, but may need more if the project has oodles of commits. Typically I use the output of the id from git log --oneline
.
的一个例子<commit sha1>
是提交 id's like 675ee6860d2c273bcc6c6a0536634a107e2a3d9f
。通常前 8-10 位数字适用于大多数项目,但如果项目有大量提交,则可能需要更多。通常我使用 id 的输出git log --oneline
。
When you get a difference of a...b and b is later than a in time it's easy to see what was changed in each file chronologically.
当您得到 a...b 的差异并且 b 在时间上晚于 a 时,很容易按时间顺序查看每个文件中的更改。
回答by Ingo Karkat
This one is similar to igorw's, but it avoids the removal of the SHA via grep
:
这个类似于igorw,但它避免了通过grep
以下方式删除 SHA :
git log --pretty='format:' --name-only HEAD^^..HEAD | sort -u
If you additionally want to see how the files were modified, replace --name-only
with --name-status
.
如果您还想查看文件是如何修改的,请替换--name-only
为--name-status
.
回答by craig Rickett
I'd use; taking the first 8 of the commit hash. If you wanted you could pipe into a file as per the below:
我会用; 取提交哈希的前 8 个。如果您愿意,可以按照以下方式输入文件:
git log 12345678..87654321 > C:\GitChanges.txt
回答by codewarrior
I use this command to compare all changes between two commits:
我使用此命令来比较两次提交之间的所有更改:
git difftool -d <commit hash1> <commit hash2>
git difftool -d <commit hash1> <commit hash2>
Like a git rebase to squash all local commits into one.
就像 git rebase 将所有本地提交压缩为一个。