Tool for searching across branches and through history in a Git repository












3















I'm looking for a tool, or for suggestions towards a script, that would be able to search a Git repository for files based on both filenames and file contents (find/grep-like). It would need to be able to search not just in the currently checked out branch, but through that branch's history as well as in other branches.



The very specific example of a Git repository that I have is a checkout of dspinellis' unix-history-repo. I often look for historical implementations of things in there, but it's a pain to track down files as I often need to guess what branch I need to be looking at (there are 165 branches in that repository).



Example of thing I would like to do with this tool is to find the wow command, which may have been an external command or a built-in command in sh or csh at some point, if it existed as part of some early BSD Unix (if it existed at all). To do this, I would want to search for wow.* as a filename pattern, and also for files that may at some point have included a wow C function, across the 165 branches of dspinellis' Git repository.










share|improve this question



























    3















    I'm looking for a tool, or for suggestions towards a script, that would be able to search a Git repository for files based on both filenames and file contents (find/grep-like). It would need to be able to search not just in the currently checked out branch, but through that branch's history as well as in other branches.



    The very specific example of a Git repository that I have is a checkout of dspinellis' unix-history-repo. I often look for historical implementations of things in there, but it's a pain to track down files as I often need to guess what branch I need to be looking at (there are 165 branches in that repository).



    Example of thing I would like to do with this tool is to find the wow command, which may have been an external command or a built-in command in sh or csh at some point, if it existed as part of some early BSD Unix (if it existed at all). To do this, I would want to search for wow.* as a filename pattern, and also for files that may at some point have included a wow C function, across the 165 branches of dspinellis' Git repository.










    share|improve this question

























      3












      3








      3








      I'm looking for a tool, or for suggestions towards a script, that would be able to search a Git repository for files based on both filenames and file contents (find/grep-like). It would need to be able to search not just in the currently checked out branch, but through that branch's history as well as in other branches.



      The very specific example of a Git repository that I have is a checkout of dspinellis' unix-history-repo. I often look for historical implementations of things in there, but it's a pain to track down files as I often need to guess what branch I need to be looking at (there are 165 branches in that repository).



      Example of thing I would like to do with this tool is to find the wow command, which may have been an external command or a built-in command in sh or csh at some point, if it existed as part of some early BSD Unix (if it existed at all). To do this, I would want to search for wow.* as a filename pattern, and also for files that may at some point have included a wow C function, across the 165 branches of dspinellis' Git repository.










      share|improve this question














      I'm looking for a tool, or for suggestions towards a script, that would be able to search a Git repository for files based on both filenames and file contents (find/grep-like). It would need to be able to search not just in the currently checked out branch, but through that branch's history as well as in other branches.



      The very specific example of a Git repository that I have is a checkout of dspinellis' unix-history-repo. I often look for historical implementations of things in there, but it's a pain to track down files as I often need to guess what branch I need to be looking at (there are 165 branches in that repository).



      Example of thing I would like to do with this tool is to find the wow command, which may have been an external command or a built-in command in sh or csh at some point, if it existed as part of some early BSD Unix (if it existed at all). To do this, I would want to search for wow.* as a filename pattern, and also for files that may at some point have included a wow C function, across the 165 branches of dspinellis' Git repository.







      git search software-rec






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Jan 10 at 15:50









      KusalanandaKusalananda

      124k16234385




      124k16234385






















          1 Answer
          1






          active

          oldest

          votes


















          2














          Heh, guess what I’ve been doing too...



          To look for a file name across all branches, I use



          git log --all --name-only --pretty=format:%H -- wow*


          wow can be replaced by any glob. This runs quite quickly on the Unix history repository. The format shows the hash leading to the creation of the matching file, so you can then check the tree out at that point and explore further.



          To search file contents across all branches, I use



          git rev-list --all | xargs git grep "excited too"


          which lists all commit objects and searches through them. This is very, very slow on the Unix history repository; listing all the branches and grepping there is quicker:



          git grep "excited too" $(git branch -r | awk '{print $1}')





          share|improve this answer


























          • This is very useful! Thanks Stephen. I will see if I can wrap these commands in convenience functions... The git rev-list --all command outputs exactly 400200 hashes (for this particular repository), so yes, I can imagine that it would be rather slow. It would include the older commits of each branch though (I presume), i.e. not just the latest version, so the search would be more thorough.

            – Kusalananda
            Jan 10 at 16:22













          • Yes, it would be more thorough ;-). Another approach specifically with the Unix history repo would be to use the source repo and associated downloads, and search those instead.

            – Stephen Kitt
            Jan 10 at 16:28











          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "106"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f493747%2ftool-for-searching-across-branches-and-through-history-in-a-git-repository%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          2














          Heh, guess what I’ve been doing too...



          To look for a file name across all branches, I use



          git log --all --name-only --pretty=format:%H -- wow*


          wow can be replaced by any glob. This runs quite quickly on the Unix history repository. The format shows the hash leading to the creation of the matching file, so you can then check the tree out at that point and explore further.



          To search file contents across all branches, I use



          git rev-list --all | xargs git grep "excited too"


          which lists all commit objects and searches through them. This is very, very slow on the Unix history repository; listing all the branches and grepping there is quicker:



          git grep "excited too" $(git branch -r | awk '{print $1}')





          share|improve this answer


























          • This is very useful! Thanks Stephen. I will see if I can wrap these commands in convenience functions... The git rev-list --all command outputs exactly 400200 hashes (for this particular repository), so yes, I can imagine that it would be rather slow. It would include the older commits of each branch though (I presume), i.e. not just the latest version, so the search would be more thorough.

            – Kusalananda
            Jan 10 at 16:22













          • Yes, it would be more thorough ;-). Another approach specifically with the Unix history repo would be to use the source repo and associated downloads, and search those instead.

            – Stephen Kitt
            Jan 10 at 16:28
















          2














          Heh, guess what I’ve been doing too...



          To look for a file name across all branches, I use



          git log --all --name-only --pretty=format:%H -- wow*


          wow can be replaced by any glob. This runs quite quickly on the Unix history repository. The format shows the hash leading to the creation of the matching file, so you can then check the tree out at that point and explore further.



          To search file contents across all branches, I use



          git rev-list --all | xargs git grep "excited too"


          which lists all commit objects and searches through them. This is very, very slow on the Unix history repository; listing all the branches and grepping there is quicker:



          git grep "excited too" $(git branch -r | awk '{print $1}')





          share|improve this answer


























          • This is very useful! Thanks Stephen. I will see if I can wrap these commands in convenience functions... The git rev-list --all command outputs exactly 400200 hashes (for this particular repository), so yes, I can imagine that it would be rather slow. It would include the older commits of each branch though (I presume), i.e. not just the latest version, so the search would be more thorough.

            – Kusalananda
            Jan 10 at 16:22













          • Yes, it would be more thorough ;-). Another approach specifically with the Unix history repo would be to use the source repo and associated downloads, and search those instead.

            – Stephen Kitt
            Jan 10 at 16:28














          2












          2








          2







          Heh, guess what I’ve been doing too...



          To look for a file name across all branches, I use



          git log --all --name-only --pretty=format:%H -- wow*


          wow can be replaced by any glob. This runs quite quickly on the Unix history repository. The format shows the hash leading to the creation of the matching file, so you can then check the tree out at that point and explore further.



          To search file contents across all branches, I use



          git rev-list --all | xargs git grep "excited too"


          which lists all commit objects and searches through them. This is very, very slow on the Unix history repository; listing all the branches and grepping there is quicker:



          git grep "excited too" $(git branch -r | awk '{print $1}')





          share|improve this answer















          Heh, guess what I’ve been doing too...



          To look for a file name across all branches, I use



          git log --all --name-only --pretty=format:%H -- wow*


          wow can be replaced by any glob. This runs quite quickly on the Unix history repository. The format shows the hash leading to the creation of the matching file, so you can then check the tree out at that point and explore further.



          To search file contents across all branches, I use



          git rev-list --all | xargs git grep "excited too"


          which lists all commit objects and searches through them. This is very, very slow on the Unix history repository; listing all the branches and grepping there is quicker:



          git grep "excited too" $(git branch -r | awk '{print $1}')






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Jan 10 at 16:17

























          answered Jan 10 at 16:11









          Stephen KittStephen Kitt

          166k24370451




          166k24370451













          • This is very useful! Thanks Stephen. I will see if I can wrap these commands in convenience functions... The git rev-list --all command outputs exactly 400200 hashes (for this particular repository), so yes, I can imagine that it would be rather slow. It would include the older commits of each branch though (I presume), i.e. not just the latest version, so the search would be more thorough.

            – Kusalananda
            Jan 10 at 16:22













          • Yes, it would be more thorough ;-). Another approach specifically with the Unix history repo would be to use the source repo and associated downloads, and search those instead.

            – Stephen Kitt
            Jan 10 at 16:28



















          • This is very useful! Thanks Stephen. I will see if I can wrap these commands in convenience functions... The git rev-list --all command outputs exactly 400200 hashes (for this particular repository), so yes, I can imagine that it would be rather slow. It would include the older commits of each branch though (I presume), i.e. not just the latest version, so the search would be more thorough.

            – Kusalananda
            Jan 10 at 16:22













          • Yes, it would be more thorough ;-). Another approach specifically with the Unix history repo would be to use the source repo and associated downloads, and search those instead.

            – Stephen Kitt
            Jan 10 at 16:28

















          This is very useful! Thanks Stephen. I will see if I can wrap these commands in convenience functions... The git rev-list --all command outputs exactly 400200 hashes (for this particular repository), so yes, I can imagine that it would be rather slow. It would include the older commits of each branch though (I presume), i.e. not just the latest version, so the search would be more thorough.

          – Kusalananda
          Jan 10 at 16:22







          This is very useful! Thanks Stephen. I will see if I can wrap these commands in convenience functions... The git rev-list --all command outputs exactly 400200 hashes (for this particular repository), so yes, I can imagine that it would be rather slow. It would include the older commits of each branch though (I presume), i.e. not just the latest version, so the search would be more thorough.

          – Kusalananda
          Jan 10 at 16:22















          Yes, it would be more thorough ;-). Another approach specifically with the Unix history repo would be to use the source repo and associated downloads, and search those instead.

          – Stephen Kitt
          Jan 10 at 16:28





          Yes, it would be more thorough ;-). Another approach specifically with the Unix history repo would be to use the source repo and associated downloads, and search those instead.

          – Stephen Kitt
          Jan 10 at 16:28


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Unix & Linux Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f493747%2ftool-for-searching-across-branches-and-through-history-in-a-git-repository%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          How to reconfigure Docker Trusted Registry 2.x.x to use CEPH FS mount instead of NFS and other traditional...

          is 'sed' thread safe

          How to make a Squid Proxy server?