0

When trying to capture git output stream to a file some of the output printed on the screen doesn't make it to the file.

to reproduce:

git show -s --oneline

the output on the console should be something similar to this:

1580ab93 (HEAD -> branch/name) some commit message

but when try to redirect the output to a file like this:

git show -s --oneline > file.txt

the output that get redirected to the file is just this:

1580ab93 some commit message

Can someone who knows the reason why this happens elaborate more and maybe suggest a solution or a workaround to be able to capture the full output from the command to my file.

Note: my final reach is to capture the output from a python script not just to a file.

Thanks

7
  • This works fine on my local Centos system. What environment are you running? Commented Nov 4, 2020 at 19:01
  • @RamanSailopal windows 10 (git for windows) Commented Nov 4, 2020 at 19:02
  • 1
    Interesting, I am getting the same results on Ubuntu. Output of git show -s --oneline is 2b202ce (HEAD -> master, origin/master, origin/HEAD) commit message but the content of tmp.txt after git show -s --oneline > tmp.txt is 2b202ce commit message. Commented Nov 4, 2020 at 19:17
  • The duplicate question does seem to answer the question. I was writing up an answer when this question got marked as a dup. I found that using the --output=<file> option worked. For example: git show -s --oneline --output="./tmp.txt" Commented Nov 4, 2020 at 19:34
  • 1
    @KarimAly So I believe the process ='s line would be process = subprocess.Popen(['git', 'show', '-s', '--oneline', '--decorate=short'], stdout=PIPE, stderr=PIPE), but I'm not sure and I can't test it. You shouldn't need the branch variable in that answer. Commented Nov 4, 2020 at 19:53

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.