1

From this SO: How to recover a dropped stash in Git?

I would like to convert this Linux command to the Windows equivalent or maybe this is command is syntacially correct for Windows, not sure about the $ and the | :

gitk --all $( git fsck --no-reflog | awk '/dangling commit/ {print $3}' )

I have tried running this cmd on my Windows Git Shell, Powershell and Cmd.exe, with my cd being a git directory, with Cmd.exe:

enter image description here

On Git Shell:

enter image description here

Which gives me the following error:

enter image description here

I have installed gawk: http://gnuwin32.sourceforge.net/packages/gawk.htm

And added C:\Program Files (x86)\GnuWin32\bin to my Path Environment Variables

Community
  • 1
  • 1
Brian Ogden
  • 18,439
  • 10
  • 97
  • 176
  • 1
    Why did you remove the `awk` bit? It matters. It is filtering the output of `git fsk --no-reflog` to only the third field of lines that contain `dangling commit` on them. Which, presumably, is just the commit hashes. So that `gitk --all` doesn't get arguments it doesn't understand. – Etan Reisner Jun 16 '15 at 20:31
  • I thought awk was a Linux only cmd, just discovering GnuWin32 – Brian Ogden Jun 16 '15 at 20:42
  • Or maybe I need "gawk" installed on my Windows machine http://gnuwin32.sourceforge.net/packages/gawk.htm – Brian Ogden Jun 16 '15 at 20:47
  • You certainly might not have awk on Windows but git-bash does I believe as do any number of other things. – Etan Reisner Jun 16 '15 at 20:48
  • git-bash has awk available. cygwin does as well, Where are you running this `gitk` command? – Etan Reisner Jun 16 '15 at 20:51
  • I have updated my question, I have tried running this 'gitk' command in Git Shell and cmd.exe, see the images I uploaded for you – Brian Ogden Jun 16 '15 at 20:58
  • awk is in the `git\bin` directory (where git itself is in `git\cmd`). You might be able to just add that to your `PATH` but I don't know that that's a good idea. You can try running it via full path in that command line call though. – Etan Reisner Jun 16 '15 at 21:05
  • 1
    Did you restart the shell (and possibly Windows) after modifying `PATH`? If they haven't seen the updated path they still won't be able to find awk. A full path in the command line should work though. – Etan Reisner Jun 16 '15 at 21:06
  • You should be able to replace `| awk '/dangling commit/ {print $3}'` with something like `| ? {$_ -match 'dangling commit'} | % {$_.Split()[2]}` in PowerShell. – Ansgar Wiechers Jun 16 '15 at 21:13
  • 1
    if you're going the `gawk` route, make sure to change your cmd-line from `awk` to `gawk`. Good luck. – shellter Jun 16 '15 at 21:23
  • Thanks for your help you all – Brian Ogden Jun 16 '15 at 21:33

2 Answers2

2

Here is the Windows PowerShell equivalent:

gitk --all $(git fsck --no-reflog | Select-String "(dangling commit )(.*)" | %{ $_.Line.Split(' ')[2] })

emragins
  • 4,607
  • 2
  • 33
  • 48
1

Ok so I had to install gawk/awk: http://gnuwin32.sourceforge.net/packages/gawk.htm

Then I updated my Path Environment Variable: C:\Program Files (x86)\GnuWin32\bin\

Then I had to restart my computer to refresh Environment Variables.

Then I could run the gitk cmd, without any changes, works fine on a Windows machine:

gitk --all $( git fsck --no-reflog | awk '/dangling commit/ {print $3}' )

But it has to be in Windows Git Shell, the cmd did not work from Windows cmd.exe.

Brian Ogden
  • 18,439
  • 10
  • 97
  • 176