从 Git Bash 管道输出到剪贴板
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18880062/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Piping output from Git Bash to clipboard
提问by Bucket
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.
Bam - 我选择的所有东西都在我的剪贴板中,我充满了喜悦。
Problem is, that's the boring way, and I like my relationship with Git to be full of excitementand glamour.
问题是,这是一种无聊的方式,我喜欢与 Git 的关系充满兴奋和魅力。
In Windows, you can pipe console output to your clipboard like-a so:
在 Windows 中,您可以像这样将控制台输出通过管道传输到剪贴板:
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 中的剪贴板,这样我就可以再次充满喜悦?
回答by madhead
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 branch | clip
对我来说很好用。clip
命令只是clip.exe
从C:\Windows\System32\
. 确保你已经clip.exe
安装在你的PATH
.
回答by j03m
copy thing.txt to clipboard
将 thing.txt 复制到剪贴板
cat thing > /dev/clipboard
Put contents of clipboard into thing.txt
将剪贴板的内容放入 thing.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 上。
回答by Bucket
@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的答案是正确的 -PATH
必须在 git-bash 中设置变量。由Cairnarvon 对超级用户的回答提供了有关如何解决此问题的详细说明:
To check what PATH
is currently set to:
要检查PATH
当前设置为:
> 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 branch | clip
:
* master
dev
dev_foo