-1

Powershell Code

Set-Location 'C:\Users\jdyun\Desktop\fsef'  #Test git repository
git show 18ba8db7d3ddf07a432d5e5ea141a2b779d33eb6:BugTrap.dll > CopiedBugTrap.dll

Copy from Powershell git command

Using Bash

Copy from Git-Bash git command

Copied binary file with git-bash is same binary file size

but, using powershell it is different file size between original and copied

I want to know why this is happening.

윤정도
  • 1
  • 1
  • Does this answer your question? [Changing PowerShell's default output encoding to UTF-8](https://stackoverflow.com/questions/40098771/changing-powershells-default-output-encoding-to-utf-8) – iRon Jun 26 '20 at 16:18
  • thx iRon!. I set default output encoing to utf-8. but it is also different file size.. TT. – 윤정도 Jun 28 '20 at 06:18

1 Answers1

2

"piping" and "redirecting output" in Powershell is a bit of a mess, and doesn't work as in bash (some would simply say : doesn't work).

You can read the answer to the question suggested by @iRon :

Changing PowerShell's default output encoding to UTF-8

Depending on your settings :

  • if the file does not begin with a BOM, powershell may try to convert the bytes in the input stream as if they were ASCII text, to a target encoding,
  • if you don't tweak your powershell settings, the target encoding defaults to UTF16,
  • even when you set the default output encoding to UTF8, I was never able to get rid of the BOM that it would so helpfully insert at the beginning of the output,
  • etc ...

Bottom line is :

  • if you want to "extract a file" using git show commit:file > content, stick to bash.
  • another way to have both versions, of course, is to rename the current version of the file, and run git checkout commit -- file.

Quoting the other answer : there seems to be a "Powershell Core" edition which should fix most of these problems ; I wasn't fortunate enough to have this version at hand when I was working with Windows ;)

LeGEC
  • 46,477
  • 5
  • 57
  • 104
  • thx for asnwering this question. Is there any way to use the powershell to start-gitbash with parameters? like 'Start-Process git-bash.exe git show :file > new_file' – 윤정도 Jun 28 '20 at 06:24
  • It's bash : `bash script.sh args...`, `bash -c "command"` ... – LeGEC Jun 28 '20 at 07:25