如何查看上次提交中更改了哪些文件

Sah*_*and 1 git

在此提交消息中,它说2个文件已被更改。

$ git commit -m "fixed .gitignore"
[master c30afbe] fixed .gitignore
 Committer: Sahand Zarrinkoub <sahandzarrinkoub@n133-p41.eduroam.kth.se>
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly. Run the
following command and follow the instructions in your editor to edit
your configuration file:

    git config --global --edit

After doing this, you may fix the identity used for this commit with:

    git commit --amend --reset-author

 2 files changed, 5 insertions(+), 4 deletions(-)
Run Code Online (Sandbox Code Playgroud)

这对我来说有点令人惊讶。我以为我只会上演一个要更改的文件。现在,我想看看哪些文件已更改以及如何更改。这是怎么做的?

And*_*ovs 15

您可以通过多种方式执行此操作。这是我在没有查看文档的情况下想到的。

$ git log -1 --name-only

commit 3c60430b752bca26bd3c80604df87ffb2ae358 (HEAD -> master, origin/master, origin/HEAD)
Author: Name Surname <name.surname@email.com>
Date:   Mon Apr 2 18:17:25 2018 +0200

    Example commit

.gitignore
README
src/main.c
Run Code Online (Sandbox Code Playgroud)

或者:

$ git log -1 --name-only --oneline

commit 3c60430 (HEAD -> master, origin/master, origin/HEAD) Example commit
.gitignore
README
src/main.c
Run Code Online (Sandbox Code Playgroud)

或者:

$ git log -1 --stat --oneline

commit 3c60430 (HEAD -> master, origin/master, origin/HEAD) Example commit
.gitignore |  2 ++
README     |  8 ++++++++
src/main.c | 12 ++++++++++++
3 files changed, 22 insertions(+)
Run Code Online (Sandbox Code Playgroud)


小智 12

获取自上次提交以来所有更改的文件

git diff --name-only HEAD HEAD~1
Run Code Online (Sandbox Code Playgroud)

  • OP:“现在,我想看看哪些文件已被更改**以及如何更改**”...所以不,这个答案只解决了所要求的一半。 (6认同)
  • 您也可以使用“^”(父提交)运算符:“git diff --name-only HEAD HEAD^”。 (3认同)
  • 你可以尝试 `git show --oneline --name-only --pretty='' HEAD` (3认同)

spr*_*tex 11

除了 Nitin Bisht 的回答之外,您还可以使用以下内容:

git log -1 --stat --oneline
Run Code Online (Sandbox Code Playgroud)

它将显示有关在上次提交中更改了哪些文件的简要信息。自然地,可以指定任意数量的提交而不是“-1”来显示在最后“-n”提交中更改的文件。

您也可以跳过传递“--no-merges”标志的合并提交:

git log -1 --stat --oneline --no-merges
Run Code Online (Sandbox Code Playgroud)


Nit*_*sht 8

您可以使用git log --stat

在此--stat将包括已修改文件的名称和路径,以及每个文件中受影响的行数。

  • 此命令将仅显示最后一次提交统计信息:`git log --stat -1` (4认同)

Jes*_*man 7

使用diff-tree

git diff-tree --no-commit-id --name-only -r <commit_hash>

  • 在 diff-tree 之后添加 -r 应该可以解决这个问题 (9认同)

小智 5

git log  // this will give you the hash-code 
git show hash-code   
Run Code Online (Sandbox Code Playgroud)