从Git Bash输出到剪贴板

时间:2022-06-09 15:42:28

I often need to relay my Git output to my ever-friendly code buddies. The best way I know how is by doing this:

我经常需要将我的Git输出传递给始终友好的代码伙伴。我知道的最好的方法就是这样做:

Right-click Git Bash title bar > Edit > Mark > Select lines > Enter

Bam - everything I selected is in my clipboard, and I am filled with joy.

我选择的一切都在我的剪贴板上,我充满了喜悦。

Problem is, that's the boring way, and I like my relationship with Git to be full of excitement and glamour.

问题是,这是无聊的方式,我喜欢我和Git的关系充满激情和魅力。

In Windows, you can pipe console output to your clipboard like-a so:

在Windows中,您可以将控制台输出传输到剪贴板like-a,以便:

C:\> dir | clip

Amazing, right? Well, when you try to do something that in Git Bash, here's what happens:

惊人的,对吧?当您尝试在Git Bash中执行某些操作时,会发生以下情况:

> git branch | clip
sh.exe": clip: command not found

And that makes me sad. Is there a way to pipe Git Bash output to my clipboard in Windows so I can once again be filled with joy?

这让我很难过。是否有一种方法可以将Git Bash输出传输到我的Windows剪贴板中,这样我就可以再次充满喜悦?

3 个解决方案

#1


36  

Well, actualy git branch | clip works fine for me. clip command just calls clip.exe from C:\Windows\System32\. Make sure you have clip.exe installed somewhere in your PATH.

好的,实际上git分支|剪辑对我来说没问题。剪辑命令只调用剪辑。exe从C:\Windows\System32\.确保你有剪辑。exe安装在路径中的某处。

#2


11  

copy thing.txt to clipboard

复制的东西。txt到剪贴板

cat thing > /dev/clipboard

Put contents of clipboard into thing.txt

把剪贴板的内容放到。txt中

cat /dev/clipboard > thing.txt

I aliased these things to pbcopy and pbpaste so I feel like I'm on my mac.

我把这些东西放在pbcopy和pbpaste上,这样我就觉得自己在mac上了。

#3


4  

@madhead's answer is correct - the PATH variable must be set from within git-bash. Here's an elaboration on how to fix this issue, courtesy of Cairnarvon's answer on superuser:

@madhead的答案是正确的——路径变量必须在git-bash中设置。以下是关于如何解决这个问题的详细说明,这是凯恩那封关于超级用户的回答:

To check what PATH is currently set to:

检查当前设置的路径为:

> echo $PATH

And to set it, assuming a 64-bit architecture:

设为64位架构:

> export PATH="$PATH:/c/Windows/System32:/c/Windows/SysWOW64"

Result of git branch | clip:

git分支|剪辑结果:

* master
  dev
  dev_foo

#1


36  

Well, actualy git branch | clip works fine for me. clip command just calls clip.exe from C:\Windows\System32\. Make sure you have clip.exe installed somewhere in your PATH.

好的,实际上git分支|剪辑对我来说没问题。剪辑命令只调用剪辑。exe从C:\Windows\System32\.确保你有剪辑。exe安装在路径中的某处。

#2


11  

copy thing.txt to clipboard

复制的东西。txt到剪贴板

cat thing > /dev/clipboard

Put contents of clipboard into thing.txt

把剪贴板的内容放到。txt中

cat /dev/clipboard > thing.txt

I aliased these things to pbcopy and pbpaste so I feel like I'm on my mac.

我把这些东西放在pbcopy和pbpaste上,这样我就觉得自己在mac上了。

#3


4  

@madhead's answer is correct - the PATH variable must be set from within git-bash. Here's an elaboration on how to fix this issue, courtesy of Cairnarvon's answer on superuser:

@madhead的答案是正确的——路径变量必须在git-bash中设置。以下是关于如何解决这个问题的详细说明,这是凯恩那封关于超级用户的回答:

To check what PATH is currently set to:

检查当前设置的路径为:

> echo $PATH

And to set it, assuming a 64-bit architecture:

设为64位架构:

> export PATH="$PATH:/c/Windows/System32:/c/Windows/SysWOW64"

Result of git branch | clip:

git分支|剪辑结果:

* master
  dev
  dev_foo