代码之家  ›  专栏  ›  技术社区  ›  Philip Fourie

如何列出提交中的所有文件?

  •  2362
  • Philip Fourie  · 技术社区  · 16 年前

    我在找一个简单的 git 命令,它提供了一个格式良好的列表,其中列出了作为哈希(sha1)提交的一部分的所有文件,没有任何无关信息。

    我已经尝试过:

    git show a303aa90779efdd2f6b9d90693e2cbbbe4613c1d
    

    虽然它列出了文件,但它也为每个文件包含不需要的差异信息。

    还有别的吗 吉特 命令,它将只提供所需的列表,以便避免从 git show 输出?

    28 回复  |  直到 6 年前
        1
  •  3132
  •   Ryan McGeary    8 年前

    首选方式 (因为它是 管道工程 命令;用于编程):

    $ git diff-tree --no-commit-id --name-only -r bd61ad98
    index.html
    javascript/application.js
    javascript/ie6.js
    

    另一种方式 (不太喜欢脚本,因为它是 瓷器 命令;面向用户)

    $ git show --pretty="" --name-only bd61ad98    
    index.html
    javascript/application.js
    javascript/ie6.js
    

    • 这个 --no-commit-id 取消提交ID输出。
    • 这个 --pretty 参数指定一个空的格式字符串,以避免开头出现损坏。
    • 这个 --name-only 参数只显示受影响的文件名(谢谢汉克)。
    • 这个 -r 参数是递归到子树
        2
  •  201
  •   Jakub Narębski adamtaub    12 年前

    如果要获取已更改文件的列表:

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

    如果要获取提交中所有文件的列表,可以使用

    git ls-tree --name-only -r <commit-ish>
    
        3
  •  193
  •   Hank Gay    16 年前

    我只是假设 gitk 不需要这样做。那样的话,试试看 git show --name-only <sha> .

        4
  •  145
  •   m13r    7 年前

    我个人使用的组合 --统计 ——在线 显示 命令:

    git show --stat --oneline HEAD
    git show --stat --oneline b24f5fb
    git show --stat --oneline HEAD^^..HEAD
    

    如果您不喜欢/不想要添加/删除统计信息,可以替换 --统计 具有 --只命名

    git show --name-only --oneline HEAD
    git show --name-only --oneline b24f5fb
    git show --name-only --oneline HEAD^^..HEAD
    
        5
  •  63
  •   lunohodov    9 年前

    最近我需要列出两次提交之间所有更改的文件。所以我使用了这个(也是*nix特定的)命令

    git show --pretty="format:" --name-only START_COMMIT..END_COMMIT | sort | uniq
    

    更新 :或者如下面Ethan指出的那样

    git diff --name-only START_COMMIT..END_COMMIT
    

    使用 --name-status 还将包括每个文件旁边的更改(添加、修改、删除等)

    git diff --name-status START_COMMIT..END_COMMIT
    
        6
  •  61
  •   Indu Devanath    10 年前

    你也可以这样做

    git log --name-only
    

    您可以浏览各种提交、提交消息和更改的文件。

    键入q返回提示。

        7
  •  52
  •   VaTo    8 年前

    最简单形式:

    git show --stat (hash)

    这很容易记住,它会提供你所需要的所有信息。

    如果您真的只需要文件名,可以添加 --name-only 选择权。

    git show --stat --name-only (hash)

        8
  •  46
  •   takeshin    12 年前

    我用 改变 别名A很常见。设置:

    git config --global alias.changed 'show --pretty="format:" --name-only'
    

    然后:

    git changed (lists files modified in last commit)   
    git changed bAda55 (lists files modified in this commit)
    git changed bAda55..ff0021 (lists files modified between those commits)
    

    可能有用的类似命令:

    git log --name-status --oneline (very similar, but shows what actually happened M/C/D)
    git show --name-only
    
        9
  •  37
  •   Vicente Quintans    8 年前

    使用标准git diff命令 (也适用于脚本编写):

    git diff --name-only <sha>^ <sha>
    

    如果还需要更改文件的状态:

    git diff --name-status <sha>^ <sha>
    

    这对合并提交很好。

        10
  •  26
  •   alpha_989 medmunds    7 年前

    使用

    git log --name-status
    

    这将向您显示提交ID、消息、更改的文件以及它是否被修改、创建、添加或删除。有点像一体式命令。

        11
  •  24
  •   Pat Notz    16 年前
    $git log 88ee8^..88ee8--仅限名称--pretty=“格式:”
    
        12
  •  18
  •   Alireza    7 年前

    好啊, 有两种方法可以显示特定提交中的所有文件…

    减少信息和 只显示姓名 在提交的文件中,您只需添加 --name-only --name-status 标记…,这些标记只显示与以前提交不同的文件名…

    所以你可以这样做 git diff 然后 --只命名 ,之后有两个提交哈希 <sha0> <sha1> ,如下所示:

    git diff --name-only 5f12f15 kag9f02 
    

    我还创建了下面的图像,以显示在这种情况下要执行的所有步骤:

    git diff --name-only 5f12f15 kag9f02

        13
  •  15
  •   user135507    15 年前

    我使用此项获取两个变更集之间的修改文件列表:

    git diff --name-status <SHA1> <SHA2> | cut -f2
    
        14
  •  15
  •   Michael De Silva    14 年前

    我喜欢使用

    git show --stat <SHA1>^..<SHA2>
    
        15
  •  13
  •   georgeok    9 年前
    git show --name-only commitCodeHere
    
        16
  •  12
  •   Koen.    9 年前

    还有 git whatchanged ,这比 git log

    NAME
           git-whatchanged - Show logs with difference each commit introduces
    

    它输出提交摘要,并在其下面列出文件及其模式,如果添加了( A (删除) D 或修改( M ;

    $ git whatchanged f31a441398fb7834fde24c5b0c2974182a431363
    

    会给出如下信息:

    commit f31a441398fb7834fde24c5b0c2974182a431363
    Author: xx <xx@xx.nl>
    Date:   Tue Sep 29 17:23:22 2015 +0200
    
        added fb skd and XLForm
    
    :000000 100644 0000000... 90a20d7... A  Pods/Bolts/Bolts/Common/BFCancellationToken.h
    :000000 100644 0000000... b5006d0... A  Pods/Bolts/Bolts/Common/BFCancellationToken.m
    :000000 100644 0000000... 3e7b711... A  Pods/Bolts/Bolts/Common/BFCancellationTokenRegistration.h
    :000000 100644 0000000... 9c8a7ae... A  Pods/Bolts/Bolts/Common/BFCancellationTokenRegistration.m
    :000000 100644 0000000... bd6e7a1... A  Pods/Bolts/Bolts/Common/BFCancellationTokenSource.h
    :000000 100644 0000000... 947f725... A  Pods/Bolts/Bolts/Common/BFCancellationTokenSource.m
    :000000 100644 0000000... cf7dcdf... A  Pods/Bolts/Bolts/Common/BFDefines.h
    :000000 100644 0000000... 02af9ba... A  Pods/Bolts/Bolts/Common/BFExecutor.h
    :000000 100644 0000000... 292e27c... A  Pods/Bolts/Bolts/Common/BFExecutor.m
    :000000 100644 0000000... 827071d... A  Pods/Bolts/Bolts/Common/BFTask.h
    ...
    

    我知道这个答案与“没有无关信息”不符,但我仍然认为这个列表比文件名更有用。

        17
  •  11
  •   skiphoppy    15 年前

    我喜欢这个:

    git diff --name-status <SHA1> <SHA1>^
    
        18
  •  9
  •   adosaiguas    11 年前

    如果只想在上次提交时更改文件列表,请使用简单的单行命令:

    git diff HEAD~1 --name-only
    
        19
  •  8
  •   Newtonx    12 年前

    列出提交时更改的文件:

    git diff --name-only SHA1^ SHA1
    

    这不会显示日志消息、额外的换行符或任何其他混乱。这适用于任何提交,而不仅仅是当前提交。不知道为什么没有 相当地 已经提到了,所以我要补充一点。

        20
  •  8
  •   Surya    9 年前

    显示日志。

    commit可以是空白(“”),也可以是sha-1或sha-1的缩写。

    git log COMMIT -1 --name-only
    

    这将只列出文件,对于进一步处理非常有用。

    git log COMMIT -1 --name-only --pretty=format:"" | grep "[^\s]"
    
        21
  •  7
  •   Ijaz Ahmad    7 年前

    找到了一个完美的答案:

    git show --name-status --oneline <commit-hash>
    

    以便我知道

    which files were just modified M
    
    Which files were newly added , A
    
    Which files were deleted , D
    
        22
  •  5
  •   Surya    9 年前

    “的组合 git show --stat “(谢谢Ryan)和几个SED命令应该为您减少数据:

    git show --stat <SHA1> | sed -n "/ [\w]\*|/p" | sed "s/|.\*$//"
    

    这将只生成修改文件的列表。

        23
  •  5
  •   srcspider    9 年前

    有一个简单的技巧可以作为文件列表查看,只需添加 : 散列之后。

    git show 9d3a52c474:
    

    然后你可以钻进去,

    git show 9d3a52c474:someDir/someOtherDir
    

    如果你点击一个文件,你会得到该文件的原始版本;如果你只是在寻找一个很好的引用或关键的代码片段(diff会让所有的东西都变得一团糟),有时候这就是你想要的。

    git show 9d3a52c474:someDir/someOtherDir/somefile
    

    这种方法的唯一缺点是它不容易显示文件树。

        24
  •  2
  •   Henry    6 年前

    如果您使用的是oh my zsh和git插件, 谷氨酸 快捷方式很有用:

    $ glg
    commit f014429013e360e1e1ef4f297b315358a5d47b5e
    Author: huhu <henry@obserbot.com>
    Date:   Tue Dec 18 07:21:11 2018 +0800
    
        Refine profile page.
    
     mini/app.json                                |  27 ++++++++-
     mini/components/postItemTwo/postItemTwo.wxml |   6 +-
     mini/pages/daren/daren.js                    |  99 ++++++++++++++++++++++++++++++++
     mini/pages/daren/daren.json                  |   3 +
     mini/pages/daren/daren.wxml                  |  16 ++++++
     mini/pages/daren/daren.wxss                  |  27 +++++++++
    
        25
  •  1
  •   Surya    9 年前
    git show HEAD@{0}
    

    对我来说很好

        26
  •  0
  •   Jignesh Joisar    6 年前

    尝试此命令以获取名称并更改行数

    git show --stat <commit-hash>
    

    仅显示文件名

    git show --stat --name-only  <commit-hash>
    

    对于get last commit hash,请尝试此命令

    git log -1 或为所有 git log

        27
  •  -1
  •   Jim Zucker    9 年前

    我想我会分享我的别名的摘要……另外,我发现使用“zsh”很好地结合了git-it的chroma键,一切都很好,并且通过更改命令提示,告诉你想要分支一直存在。

    对于SVN提供的内容,您会发现这很有用:(这是来自不同线程的想法的组合,我只相信知道如何使用复制/粘贴)

    .gitconfig:
            ls = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)%an%Creset' --abbrev-commit --date=relative --name-status
    
    >>git ls
    * 99f21a6 - (HEAD -> swift) New Files from xcode 7 (11 hours ago) Jim Zucker| 
    | A     icds.xcodeproj/project.pbxproj
    | A     icds.xcodeproj/project.xcworkspace/contents.xcworkspacedata
    | A     icds/AppDelegate.m
    | A     icds/Assets.xcassets/AppIcon.appiconset/Contents.json
    
    * e0a1bb6 - Move everything to old (11 hours ago) Jim Zucker| 
    | D     Classes/AppInfoViewControler.h
    | D     Classes/AppInfoViewControler.m
    | D     Classes/CurveInstrument.h
    
    
    .gitconfig: 
           lt = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)%an%Creset' --abbrev-commit --date=relative
    
    >>git lt
    * 99f21a6 - (HEAD -> swift) New Files from xcode 7 (11 hours ago) Jim Zucker
    * e0a1bb6 - Move everything to old (11 hours ago) Jim Zucker
    * 778bda6 - Cleanup for new project (11 hours ago) Jim Zucker
    * 7373b5e - clean up files from old version (11 hours ago) Jim Zucker
    * 14a8d53 - (tag: 1.x, origin/swift, origin/master, master) Initial Commit (16 hours ago) Jim Zucker
    
    
    .gitconfig
    lt = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)%an%Creset' --abbrev-commit --date=relative
    
    >> git lt
    
    commit 99f21a61de832bad7b2bdb74066a08cac3d0bf3c
    Author: Jim Zucker <jim@stratengllc.com>
    Date:   Tue Dec 1 22:23:10 2015 -0800
    
        New Files from xcode 7
    
    A       icds.xcodeproj/project.pbxproj
    A       icds.xcodeproj/project.xcworkspace/contents.xcworkspacedata
    
    
    commit e0a1bb6b59ed6a4f9147e894d7f7fe00283fce8d
    Author: Jim Zucker <jim@stratengllc.com>
    Date:   Tue Dec 1 22:17:00 2015 -0800
    
        Move everything to old
    
    D       Classes/AppInfoViewControler.h
    D       Classes/AppInfoViewControler.m
    D       Classes/CurveInstrument.h
    D       Classes/CurveInstrument.m
    
        28
  •  -2
  •   4067098    7 年前

    这应该有效:

    git status
    

    这将显示什么是非阶段性的和什么是阶段性的。

    推荐文章