Reputation: 1296
I'm executing the following command in Powershell.
git log --branches --not --remotes --oneline
The goal is to get all non-pushed commits on all branches. Git displays the name of the branch in the output (in a different color). When I try to capture the command with
$foo = git log --branches --not --remotes --oneline
the variable $foo
is missing the colored output. So it's not the same as what gets displayed on the screen.
How can I capture the same output that would be displayed?
Update Just to clarify, I don't care about the output being in color. My point was only that the colored output is not being captured at all, in color or not
Upvotes: 2
Views: 185
Reputation: 5938
This is not a PowerShell issue but actually with Git. Git changes the output depending on how the output is processed. In GNU/Linux, for example:
$ git log --branches --not --remotes --oneline
314129a (HEAD -> master) Generate Bootstrap rules with mode classes.
...
If I pipe it through cat
for example then the output changes to:
$ git log --branches --not --remotes --oneline | cat
314129a Generate Bootstrap rules with mode classes.
...
It wasn't just the colour in your example as the parantheses were removed as well.
What you are seeing in PowerShell is the same behaviour:
PS> git log --branches --not --remotes --oneline
d331837 (HEAD -> master) Fixed issue with comparisons.
And then piped through something:
PS> git log --branches --not --remotes --oneline | Out-String
d331837 Fixed issue with comparisons.
And so to fix the problem you need to tell Git to generate output in a specific way, e.g.
$foo = git log --branches --not --remotes --oneline --decorate=short
Upvotes: 1