代码之家  ›  专栏  ›  技术社区  ›  Sahand

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

git
  •  72
  • Sahand  · 技术社区  · 8 年前

    在此提交消息中,它表示有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(-)
    

    这让我有点惊讶。我以为我只准备了一个要更改的文件。现在,我想看看哪些文件已经更改,以及如何更改。这样做的方法是什么?

    6 回复  |  直到 8 年前
        1
  •  134
  •   Robin He    7 年前

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

    git diff --name-only HEAD HEAD~1
    
        2
  •  117
  •   Nitin Bisht    6 年前

    你可以试试 git log --stat

    在这里 --stat 将显示每次提交更改的每个文件的插入和删除次数。

    示例: 下面提交在 Demo.java 文件并删除了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(-)
    
        3
  •  23
  •   Andrejs Cainikovs    8 年前

    您可以通过多种方式实现这一点。这就是我在没有查看文档的情况下想到的。

    $ 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(+)
    
        4
  •  12
  •   sprutex    6 年前

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

    git log -1 --stat --oneline
    

    它将显示上次提交中更改的文件的压缩信息。当然,可以指定任意数量的提交来代替“-1”,以显示在上一次“-n”提交中更改的文件。

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

    git log -1 --stat --oneline --no-merges
    
        5
  •  4
  •   user6080689 user6080689    8 年前
    git log  // this will give you the hash-code 
    git show hash-code   
    
        6
  •  2
  •   Jesferman    8 年前

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