I have encountered the following command in an internet tutorial. I couldn't understand how it works.

git log | grep commit  > ~/filename.txt

Someone please explain me how it works.

  • 2
    what does the tutorial say about the command line? ... what is it supposed to do? – jsotola Aug 5 '19 at 7:02
  • Have you tried to find out what git log does and what grep does? – Philippos Aug 5 '19 at 7:22
  • Which bit are you stuck on? git or grep or > or … Note git is not easy to use, see cseducators.stackexchange.com/q/2897/204 – ctrl-alt-delor Aug 5 '19 at 8:55
  1. git log outputs the Git history.
  2. The pipe (|) instructs the shell to pass the output as a data stream into grep.
  3. grep will extract all the lines containing the string commit from the output of git log.
  4. > redirects the result of grep to the file filename.txt in the home directory (~).

You can safely try this out.

Change into a directory with a git repo. Try "git log" to see what ist does. ( Git Basics here )

Then do "git log| grep commit" to see what it does.

Then try the entire command and have a look at the file "filename.txt" that will appear in your home directory.

After that, you may want to check the manpages for both git and grep. And maybe have a look at the Advanced Bash Scripting Guide, which is very valuable resource I have made many uses of myself.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.