Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why does only part of git console output go into log file?

On Windows, I have a bat file that creates a git commit like so:

@echo off
echo.
echo -------------------------

cd C:\Repository\Other\notes-repo
git add --all
git commit -m "autoCommit"
git push
cd C:\Repository\Other

I call it from the command line like this:

note_repo_sync.bat >> log.txt 2>&1

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

When there are changes to the repo, then this gets added to the log file:

-------------------------

[main 013c443] autoCommit
 1 file changed, 1 deletion(-)
To https://github.com/raelb/notes-repo.git
   6bceead..013c443  main -> main

However, if I omit the 2>&1, i.e. print the stderr to console, then much more is shown:

C:\Repository\Other>notes_repo_sync.bat >> log.txt
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 4 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 290 bytes | 290.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To https://github.com/raelb/notes-repo.git
   28a2bf3..691fb4f  main -> main

Why are the extra lines (Enumerating objects etc..) not included in the log when I append 2>&1 to the command line?

>Solution :

Both git fetch and git push write their progress information (--progress output, suppressed with --no-progress) to standard error. Progress output is suppressed by default when stderr is not connected to a terminal.1

There’s no particularly good reason for this, other than "Git used to do this for historical reasons, so Git still does this for historical reasons".


1There are, or were, further bugs where explicit --progress didn’t always work to restore the stderr output even when stderr is connected to something other than a terminal.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading