gpt4 book ai didi

git - 不同git搜索命令的区别

转载 作者:太空狗 更新时间:2023-10-29 14:10:58 26 4
gpt4 key购买 nike

一个初学者的问题:有几种方法可以在 git 历史中进行搜索。
对我来说,不清楚是什么,命令之间的区别真的是:

  • git log ,例如git log -S 'for what you search' --all在所有分支中搜索字符串并git log -G 'search for regexpr' --all搜索正则表达式。参见例如 here
  • git log --grep 'pattern'
  • git rev-list ,例如git rev-list --grep='string' --all
  • git grep ,例如git grep "string or regexpr" $(git rev-list --all)来自 here
  • gitk ,例如gitk file.txt一个gui界面
  • git log --all --full-history -- **/thefile.*here 在历史中搜索文件名.
  • git diff --word-diff-regex=. > changes.txt结合 grep -oP '\+[^\+]+\+' changes.txt | tr -d '\+'以字符为基础显示更改。来自 here .如果尚未提交更改,这甚至有效。

  • 我不好的理解是
  • git log在提交消息中搜索?好像是基于rev-list ?来自文档:

  • Shows the commit logs. The command takes options applicable to the git rev-list command to control what is shown and how, and options applicable to the git diff-* commands to control how the changes each commit introduces are shown.


  • git-rev-list似乎是一个更基本的命令,因为它对提交对象(或树对象?)进行操作。来自文档:

  • git-rev-list - Lists commit objects in reverse chronological order


  • git grep似乎到处搜索:在文件、blob、树和提交对象中?来自文档:

  • git-grep - Print lines matching a pattern. Look for specified patterns in the tracked files in the work tree, blobs registered in the index file, or blobs in given tree objects. Patterns are lists of one or more search expressions separated by newline characters. An empty string as search expression matches all lines.



    我用了 Git book作为引用。

    最佳答案

    git log searches in the commit messages?



    是的。选项 -S/-G搜索更改出现次数(即添加或删除)提及的文本的提交。 --grep搜索整个提交消息。

    git grep seems to search everywhere: in files, blobs, trees and commit objects?



    不,仅在文件中(即 blob)。

    关于git - 不同git搜索命令的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47307978/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com