【问题标题】:How to figure out if each file is added, modified or deleted in a commit? [duplicate]如何确定提交中是否添加、修改或删除了每个文件? [复制]
【发布时间】:2021-06-23 10:12:54
【问题描述】:

如果我已经是提交的hash,并且需要知道这次提交时添加了哪些文件,修改了哪些文件,删除了哪些文件,我该怎么办?

让我具体一点。在commit 6128373中,新增added1.txt,修改modified.txt,删除deleted.txt

我试过git show ,输出如下。它确实有我想要的,但是有太多不需要的细节,比如行间差异。

$ git show 6128373                                              
commit 61283738b68b3e9e8d06dc5b9fdb722a43fe33cb (HEAD -> master)
Date:   Wed Jun 23 17:35:17 2021 +0800                          
                                                                
    add modify delete                                           
                                                                
diff --git a/added1.txt b/added1.txt                            
new file mode 100644                                            
index 0000000..53bf775                                          
--- /dev/null                                                   
+++ b/added1.txt                                                
@@ -0,0 +1 @@                                                   
+added                                                          
\ No newline at end of file                                     
diff --git a/deleted.txt b/deleted.txt                          
deleted file mode 100644                                        
index e69de29..0000000                                          
diff --git a/modified.txt b/modified.txt                        
index d8263ee..1234e84 100644                                   
--- a/modified.txt                                              
+++ b/modified.txt                                              
@@ -1 +1,2 @@                                                   
-2                                                              
\ No newline at end of file                                     
+2                                                              
+3                                                              
\ No newline at end of file  

                               

我试过git log 6128373,输出如下。它没有我想要的,它显示了我不关心的提交。

commit 61283738b68b3e9e8d06dc5b9fdb722a43fe33cb (HEAD -> master)
Author: 
Date:   Wed Jun 23 17:35:17 2021 +0800

    add modify delete

commit 044e02554997346accf215b3c8022e15751973d9
Author: 
Date:   Wed Jun 23 17:34:42 2021 +0800

    a
...
...

我试过了

$ git diff --name-only 6128373~ 6128373
added1.txt
deleted.txt
modified.txt

它不显示哪些文件被添加|删除|修改

【问题讨论】:

标签: git


【解决方案1】:

我认为您缺少包含 --name-status 选项

参考:https://git-scm.com/docs/git-show#Documentation/git-show.txt---name-status

--name-status

仅显示更改文件的名称和状态。有关状态字母的含义,请参阅 --diff-filter 选项的描述。就像 --name-only 一样,文件名通常以 UTF-8 编码。

例子

git show --name-status <commitID> 

【讨论】:

    猜你喜欢
    • 2015-07-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-24
    • 2020-04-07
    • 2014-05-11
    • 1970-01-01
    • 2014-10-19
    相关资源
    最近更新 更多