Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
112 views
in Technique[技术] by (71.8m points)

logging - In Visual Studio Code, is there a way to get a merged git log of all git commands from both Source Control pane and Terminal window?

This is a spin-off from In Visual Studio Code, how can I get a git log of all git commands executed in the Source Control pane?

The question is how to get a merged log of the Source Control pane (that the link already explains) with the log of the Terminal window. At best commands + their output, most important is the sequence of the commands.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I expected vscode to offer a ready-made merged log. Instead, up to now, manual work seems needed.

The only automatically merged log of Source Control pane and Terminal view is in the vscode "Developer Tools" > "console", with the caveat that the terminal commands are not logged directly: you only see from a certain structure that there was a terminal command at that moment and then you can at least manually look up in your terminal history what it must have been - tricky, but not impossible if you desparately need to document or reconstruct the exact command sequence. Still you need the manual work here to assign the terminal commands to the right place in the Developer Tools console log.

There are other logs which do not include both, just either the Source Control pane or the Terminal view.


UPDATE, taken from a comment at History or log of commands executed in Git:

A hackish approach to record everything would be to replace the git binary with a shellscript (or whatever) that logs all arguments and then calls the original binary forwarding the same arguments.

In this case, this "original binary" would be vscode's git menu so that vscode's internal git commands that you select in the menu but that are not logged in the terminal are logged as well in addition to the terminal commands.

You would need to be able to steer vscode's internal git menu from the terminal for that, and that is probably a lot of interface work and not realistic. (My understanding of the issue could be wrong here, I am just guessing.)


The easiest manually merged log is obviously the manual merger of the Git Output window (see In Visual Studio Code, how can I get a git log of all git commands executed in the Source Control pane?) manually put together with simple copies from the terminal commands+output.

There are other logs available which do not add any more value, for completeness: git reflog, git.txt, and history command in Terminal window.

Here is a detailed documentation which can probably be ignored because the manual merge of git log and terminal log should be the easiest way.

####

vscode Developer Tools console:

  • run "C:UsersUSERAppDataLocalProgramsMicrosoft VS CodeCode.exe" --verbose or if it is in your Path just run code --verbose` from the command line.

  • in Code select Help | Toggle Developer Tools and select the Console

  • Find out which filters you need, e.g. a filename for a first test, or if you want to see only the Source Control pane commands, filter for "CommandService". You need to play around to find out, perhaps you just copy the whole log and filter it later.

Example: put a filter on "git -Watcher", search for "init" gives me:

TRACE telemetry/views.welcomeAction {viewId: "workbench.scm", uri:

"command:git.init?%5Btrue%5D"}

TRACE CommandService#executeCommand

git.init

vscode uses git.stage instead of git.add, which are synonyms, see Differencies between git add and git stage command

The search for a project file leads to the "DecorationsService" after the git.commit.

Terminal commands cannot be seen directly, but you see from the "typing information" in the terminal that there was an input in the terminal:

TRACE IPty#write [number] characters

followed by 4 "File Watcher" actions (tested with git status).

Though you cannot see the commands, you can reconstruct their sequence even when you have switched between Source Control pane and Terminal window.

Mind that this is just a session log in contrast to the saved git reflog. And it does not include any output.

####

git reflog:

For a global solution, there is the git reflog which has only commit/checkout/merge… log and does not show the exact command / output, but a summary, this is borrowed from History or log of commands executed in Git

Taken from a comment at History or log of commands executed in Git again:

The reflog doc says: "record when the tips of branches and other references were updated in the local repository".

####

git.txt:

vscode offers a git log, on Windows, this is C:UsersUSERAppDataRoamingCodelogs[some hash]git.txt

For more details and other locations, see Where are Visual Studio Code log files?

It starts like

telemetry/git.command {"properties":{"command":"git.init" …

####

Terminal history:

For the terminal history of commands, use history in the vscode terminal, this is borrowed again from History or log of commands executed in Git

This is just a session log in contrast to the saved git reflog.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...