0

I have two branches: master and working. I'm currently on the working branch, but I want to reference a file which only exists in the master branch, without checking out that branch. Is there some shell syntax which lets me reference that file in branch master?

For example:

$ some-tool git:master!some-file.txt
Jeff
  • 11
  • 4

2 Answers2

0

No, but using process substitution you can generate a path that corresponds to a FIFO attached to an arbitrary command's output. Thus, if the "arbitrary command" retrieves your file from git (and your tool can read from a FIFO rather than needing a seekable file), there you are.

some-tool <(git show master:some-file.txt)
Charles Duffy
  • 280,126
  • 43
  • 390
  • 441
0

If you're using bash, or another shell that supports process substitution, this should work:

$ some-tool <(git show <BRANCH>:<PATH_FROM_GITROOT>)

<() creates a file handle in /dev/fd or a named pipe depending on implementation, which contains the content of the subcommand AFAIK.

Carey
  • 650
  • 1
  • 4
  • 16
  • Heh. 14 seconds apart. BTW, this is a feature bash borrowed from ksh, so while it's not available in POSIX sh, neither is it bash-only. – Charles Duffy Feb 14 '18 at 23:16
  • ...btw, while `/dev/fd` is how it works on Linux, when compiled on platforms where the kernel doesn't offer that facility bash will use a named pipe instead. – Charles Duffy Feb 14 '18 at 23:17
  • Wasn't aware that is isn't bash only, I'm aware that zsh has its own different equivalent so I just assumed it was a bashism. Also wasn't aware you could get a named pipe from this, will update answer. – Carey Feb 14 '18 at 23:20
  • Thanks to both @Carey – Jeff Feb 16 '18 at 00:09