有时,git建议git rm --cached
取消暂存文件git reset HEAD file
.我什么时候应该使用哪个?
编辑:
D:\code\gt2>git init
Initialized empty Git repository in D:/code/gt2/.git/
D:\code\gt2>touch a
D:\code\gt2>git status
# On branch master
#
# Initial commit
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# a
nothing added to commit but untracked files present (use "git add" to track)
D:\code\gt2>git add a
D:\code\gt2>git status
# On branch master
#
# Initial commit
#
# Changes to …
Run Code Online (Sandbox Code Playgroud) 我注意到当我使用期望其他函数作为参数的函数时,我有时可以这样做:
someFunction(firstParam,anotherFunction)
Run Code Online (Sandbox Code Playgroud)
但其他时候,编译器给我一个错误,告诉我应该编写一个这样的函数,以便将它视为部分应用的函数:
someFunction(firstParam,anotherFunction _)
Run Code Online (Sandbox Code Playgroud)
例如,如果我有这个:
object Whatever {
def meth1(params:Array[Int]) = ...
def meth2(params:Array[Int]) = ...
}
import Whatever._
val callbacks = Array(meth1 _,meth2 _)
Run Code Online (Sandbox Code Playgroud)
为什么我不能拥有如下代码:
val callbacks = Array(meth1,meth2)
Run Code Online (Sandbox Code Playgroud)
在什么情况下编译器会告诉我添加_
?
如果我有这个:
val a = Array(...)
Run Code Online (Sandbox Code Playgroud)
我写
a.par.map(e => someFunc(e))
Run Code Online (Sandbox Code Playgroud)
生成的集合是否与非并行集合的顺序相同?
想象一下文件1:
#include "first.h"
#include "second.h"
#include "third.h"
// more code here
...
Run Code Online (Sandbox Code Playgroud)
想象一下文件2:
#include "fifth.h"
#include "second.h"
#include "eigth.h"
// more code here
...
Run Code Online (Sandbox Code Playgroud)
我想获取文件2中包含的标题,但不是文件1中的标题,只是那些行.因此,当运行时,文件1和文件2的差异将产生:
#include "fifth.h"
#include "eigth.h"
Run Code Online (Sandbox Code Playgroud)
我知道如何在Perl/Python/Ruby中实现它,但我想在不使用不同编程语言的情况下完成此任务.
为什么git允许我重置文件?我以为我理解了reset
,因为它正在移动HEAD ...显然我错了.
所以,git reset sha file
似乎做同样的事情git checkout sha file
,除了我file
在索引和工作目录中看到的.
这对我来说没有意义.有人可以解释一下这个区别吗?
我用sbt 0.10
.
我在.sbt
文件中有以下设置:
scalacOptions += "-usejavacp"
Run Code Online (Sandbox Code Playgroud)
问题是当Scala编译器执行并scalacOptions
设置时:
[debug] Calling Scala compiler with arguments (CompilerInterface):
[debug] -usejavacp
[debug] -d
[debug] D:\project\target\scala-2.8.1.final\classes
[debug] -bootclasspath
...
Run Code Online (Sandbox Code Playgroud)
该-usejavacp
参数出现在导致此错误的实际Scala jar之前:
scala.collection.mutable.ListBuffer does not take type parameters
Run Code Online (Sandbox Code Playgroud)
是否有附加参数的方法而不是前缀?我也尝试过,++= Array("-usejavacp")
但结果是一样的.
$ git svn clone -s http://a_repo local_dir ( by default this brings me r1 ) to hdd
Initialized empty Git repository in d:/Temp/local_dir/.git/
r1 = some_SHA (refs/remotes/trunk)
$ cd local_dir
$ git svn rebase
fatal: ambiguous argument 'HEAD': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions
log --no-color --no-decorate --first-parent --pretty=medium HEAD: command returned error: 128
Run Code Online (Sandbox Code Playgroud)
我怎样才能真正结帐回购?
我也试过没有变形,使用fetch
,但它一次只带一个修订版.我们有几千次提交,按照这个速度,复制存储库需要几天时间.
我真的很喜欢Tie :: File,它允许你将tie
数组转换为文件的行.您可以以任何方式修改数组,当您完成它时,您untie
可以相应地修改该文件的内容.
我想在Scala中重新实现这种行为,这是我到目前为止所做的:
class TiedBuffer(val file:File) extends ArrayBuffer[String] {
tieFile
def untie = {
val writer = new PrintStream(new FileOutputStream(file))
this.foreach(e => writer.println(e))
writer.close
this
}
private def tieFile = this ++= scala.io.Source.fromFile(file).getLines()
}
Run Code Online (Sandbox Code Playgroud)
但是,ArrayBuffer上定义的"运算符"返回各种类,不同于我自己的类,例如:
println((new TiedBuffer(somefile) +: "line0").getClass)
Run Code Online (Sandbox Code Playgroud)
给了我一个immutable.Vector
.我可以将类限制为一组非常小的预定义方法,但我认为如果我可以提供所有这些方法(foreach/map/...)会很好.
我应该继承什么,或者我应该如何解决这个问题,以便我有一个类似流体的数组接口,它允许我修改文件的内容?
BOUNTY:为了赢得赏金,你能展示一个可以CanBuildFrom
用来完成这项任务的工作实例吗?
想象一下:
val myObject = if(someCondition) {
new Whatever with Trait1
} else if(otherCondition) {
new Whatever with Trait2 with Trait3 with Trait4
} else {
new Whatever with Trait5
}
Run Code Online (Sandbox Code Playgroud)
myObject
对象是否在运行时"组合",或者scala编译器是否足够智能以在编译时生成适当的代码?如果您有多个地方正在应用上述代码中的特征,它会对代码产生什么样的性能影响?
假设我有这个系列:
val a = Array(Array(1,2,3,4,5),Array(4,5),Array(5),Array(1,2,6,7,8))
Run Code Online (Sandbox Code Playgroud)
有没有办法定义一个可以按以下方式工作的提取器:
a.foreach(e => {
e match {
case Array( ending with 5 ) =>
case _ =>
}
})
Run Code Online (Sandbox Code Playgroud)
对不起伪代码,但我不知道如何表达它.有没有办法匹配5个作为最后一个元素的东西?如果我想匹配第一个元素为1而最后一个元素为5的东西怎么办?这适用于各种长度的数组(请注意,我在示例中为我的数组特别选择了不同的长度).
谢谢!
假设我在文件中包含此文本:
/home is where the heart is.
Run Code Online (Sandbox Code Playgroud)
例如,如果我选择/home
文本,使用C-spc,有没有办法将它发送到ls,那么最终是否会执行ls /home
?M-|
不起作用.
我有一系列的行,就像在这个代码片段中一样:
def insertBeforeLine(text:String,whichLine:String,what:String) = {
val lines = text.lines
lines.foldLeft(ListBuffer[String]())((acumulator,element) => {
acumulator ++ { if(element == whichLine) Array(what,element) else Array(element) }
}).mkString("\n")
}
Run Code Online (Sandbox Code Playgroud)
我试图在每一行等于之前预先添加一些东西whichLine
.有更好/更清洁的方式吗?例如,如果我的输入是:
line1
line2
line4
Run Code Online (Sandbox Code Playgroud)
我调用我的函数insertBeforeLine(input,"line4","line3")
会产生:
line1
line2
line3
line4
Run Code Online (Sandbox Code Playgroud) 这编译:
def fibonacci():() => Int = {
var first = 1
var second = 2
return () => {
val oldFirst = first
first = second
second = second + oldFirst
second
}
}
Run Code Online (Sandbox Code Playgroud)
这不是:
def fibonacci():() => Int = {
var first = 1
var second = 2
return ():Int => {
val oldFirst = first
first = second
second = second + oldFirst
second
}
}
Run Code Online (Sandbox Code Playgroud)
我明确地试图告诉它我正在返回一个Int,但是我得到了这个错误:Illegal start of declaration
并且它指向该first = second
行.他们有什么不同?我正在使用Scala 2.8.1.