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

yh2wf1be  于 2023-02-20  发布在  Git
关注(0)|答案(7)|浏览(151)

在这个提交消息中,它说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(-)

这对我来说有点意外。我以为我只暂存了一个要更改的文件。现在,我想看看哪些文件已经更改以及如何更改。如何进行此操作?

ijnw1ujt

ijnw1ujt1#

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

git diff --name-only HEAD HEAD~1
hxzsmxv2

hxzsmxv22#

你可以试试git log --stat
这里--stat将显示每次提交更改的每个文件的插入和删除次数。

**示例:**以下提交向Demo.java文件添加了67行,删除了38行:

commit f2a238924456ca1d4947662928218a06d39068c3
Author: X <X@example.com>
Date: Fri May 21 15:17:28 2020 -0500
Add a new feature
Demo.java | 105 ++++++++++++++++++++++++-----------------
1 file changed, 67 insertion(+), 38 deletions(-)
mcdcgff0

mcdcgff03#

你可以用很多方法来做这件事。这是我在没有看文档的情况下想出来的。

$ 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

或者:

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

commit 3c60430 (HEAD -> master, origin/master, origin/HEAD) Example commit
.gitignore
README
src/main.c

或者:

$ 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(+)
92dk7w1h

92dk7w1h4#

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

git log -1 --stat --oneline

它将显示上次提交中哪些文件被修改的压缩信息。当然,可以指定任意数量的提交来显示上次“-n”提交中修改的文件,而不是“-1”。
您也可以跳过传递“--no-merges”标志的合并提交:

git log -1 --stat --oneline --no-merges
v9tzhpje

v9tzhpje5#

git log  // this will give you the hash-code 
git show hash-code
qoefvg9y

qoefvg9y6#

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

lnlaulya

lnlaulya7#

这是我的首选

git show --name-status --pretty=""

或者,如果我只需要文件名:

git show --name-only --pretty=""

git show还提供了其他功能,如--stat

相关问题