尝试使用rebase HEAD~5 and squash 5 commits together into 1
,ruby
从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
任何想法如何使其工作以及改进什么?
答案 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