在 Windows 上,我有一個 bat 檔案,它可以像這樣創建一個 git 提交:
@echo off
echo.
echo -------------------------
cd C:\Repository\Other\notes-repo
git add --all
git commit -m "autoCommit"
git push
cd C:\Repository\Other
我像這樣從命令列呼叫它:
note_repo_sync.bat >> log.txt 2>&1
當 repo 發生更改時,它會被添加到日志檔案中:
-------------------------
[main 013c443] autoCommit
1 file changed, 1 deletion(-)
To https://github.com/raelb/notes-repo.git
6bceead..013c443 main -> main
但是,如果我省略2>&1
,即將 stderr 列印到控制臺,則會顯示更多內容:
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
2>&1
當我附加到命令列時,為什么額外的行(列舉物件等)不包含在日志中?
uj5u.com熱心網友回復:
兩者都git fetch
將git push
它們的進度資訊(--progress
輸出,用 抑制--no-progress
)寫入標準錯誤。當 stderr 未連接到終端時,默認情況下會抑制進度輸出。1
沒有什么特別好的理由,除了“Git 曾經出于歷史原因這樣做,所以 Git 仍然出于歷史原因這樣做”。
1存在或曾經存在更多錯誤,--progress
即使 stderr 連接到終端以外的其他東西,顯式并不總是可以恢復 stderr 輸出。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/504889.html