使用git rebase命令将Vim警告I / O重定向到终端或从终端重定向

时间:2013-12-08 11:20:12

标签: ruby git vim

尝试使用rebase HEAD~5 and squash 5 commits together into 1ruby从10个虚拟提交中system command。    使用vim作为默认编辑器并收到此错误:

# ERROR
# Vim  warning: output does not redirect on terminal
# Vim  warning: input does not come from terminal

尝试做:

# DESIRED
# 1. open VIM terminal window
# 2. manualy select files for squashing

#!/usr/bin/env ruby

# create dummy files
1.upto(10) { |i| `touch  "file#{i}.txt"`  }

files = Dir.glob('*.txt')

# initialize repo
`git init`

# commit each file separately
files.each do |f|
`git add #{f}`
`git commit -m "add #{f} to repo"`
end

# rebasing
`git rebase -i HEAD~5`
# error 

任何想法如何使其工作以及改进什么?

1 个答案:

答案 0 :(得分:1)

上面代码的问题是你试图使用反引号运算符从ruby运行一个外部命令(在这种情况下,通过git的inbuilt rebase命令vim)。

相反,请为此目的尝试使用system命令 参考:http://www.ruby-doc.org/core-2.0.0/Kernel.html#method-i-system

因此,更正的代码将是:

#!/usr/bin/env ruby

# DESIRED
# 1. open VIM terminal window
# 2. manualy select files for squashing

# create dummy files
1.upto(10) { |i| `touch  "file#{i}.txt"`  }

files = Dir.glob('*.txt')

# initialize repo
system "git init"

# commit each file separately
files.each do |f|
system "git add #{f}"
system "git commit -m 'add #{f} to repo'"
end

# rebasing
system "git rebase -i HEAD~5"
# error