所以,我正在分支A中处理一个文件,并且即将准备提交它。然而,在查看差异时,我认为最好将其分成两个单独的提交(在这种情况下,也许是两个单独的分支)。我之前已经使用git add --patch来分别暂存不同的块,因此我认为我可以使用它。问题是,我需要拆分其中的一个块。运行git add --patch SdA.py
并使用e
来编辑问题块...
# Manual hunk edit mode -- see bottom for a quick guide
@@ -50,13 +50,74 @@ import PIL.Image as im
import constant
+
+def exp_range(min=None, max=None, step=None):
+ """
+ Generate an exponentially increasing value scaled and offset such
+ that it covers the range (min, max]. Behaviour is similar to
+ exp(x), scaled such that the final value generated is equal to
+ 'max'. 'step' defines the granularity of the exponential
+ function. The default value is 5, corresponding to a step-size
+ of tau.
+
+ :type min: float
+ :param min: minimum value of range (offset)
+
+ :type max: float
+ :param max: Maximum (final) value of range
+
+ :type step: int
+ :param step: Number of incremental steps within the range
+ (min, max]
+
+ """
+ if min is None:
+ raise StopIteration
+
+ # One input argument (same as range(10))
+ if min is not None and max is None and step is None:
+ step = min
+ min = 0.
+ max = 1.
+ elif step is None:
+ step = 5
+
+ for i in xrange(step):
+ exp_rate = np.exp(i - (step-1))
+ yield min + (max - min) * exp_rate
+ raise StopIteration
+
+
def norm(input):
+ """
+ Return the norm of a vector or row-wise norm of a matrix
+
+ :type input: theano.tensor.TensorType
+ :param input: Theano array or matrix to take the norm of.
+
+ """
return T.sqrt((input * input).sum(axis=0))
def normalize(vector, scale=1.0, offset=0.5):
+ """
+ Normalize (Zero and scale) a vector such that it's peak to peak
+ value is equal to 'scale', and it is centered about 'offset'.
+
+ :type vector: numpy.ndarray
+ :param vector: Vector to normalize to the given parameters.
+
+ :type scale: float
+ :param scale: Peak-to-peak range to stretch or shrink the vector's
+ current peak-to-peak range to.
+
+ :type offset: float
+ :param offset: Value at which to center the peak-to-peak range at.
+
+ """
return (vector - vector.min()) * scale / vector.ptp()
+
没问题。底部有一个迷你指南,我明白了。所以,我们想把新的功能放在这个提交中,而其他功能的文档放在另一个提交中。根据迷你文档:# 要删除“+”行,请将它们删除。
# Manual hunk edit mode -- see bottom for a quick guide
@@ -50,13 +50,74 @@ import PIL.Image as im
import constant
+
+def exp_range(min=None, max=None, step=None):
+ """
+ Generate an exponentially increasing value scaled and offset such
+ that it covers the range (min, max]. Behaviour is similar to
+ exp(x), scaled such that the final value generated is equal to
+ 'max'. 'step' defines the granularity of the exponential
+ function. The default value is 5, corresponding to a step-size
+ of tau.
+
+ :type min: float
+ :param min: minimum value of range (offset)
+
+ :type max: float
+ :param max: Maximum (final) value of range
+
+ :type step: int
+ :param step: Number of incremental steps within the range
+ (min, max]
+
+ """
+ if min is None:
+ raise StopIteration
+
+ # One input argument (same as range(10))
+ if min is not None and max is None and step is None:
+ step = min
+ min = 0.
+ max = 1.
+ elif step is None:
+ step = 5
+
+ for i in xrange(step):
+ exp_rate = np.exp(i - (step-1))
+ yield min + (max - min) * exp_rate
+ raise StopIteration
+
+
def norm(input):
return T.sqrt((input * input).sum(axis=0))
def normalize(vector, scale=1.0, offset=0.5):
return (vector - vector.min()) * scale / vector.ptp()
那看起来不错。让我们添加它...
error: patch failed: SdA.py:50
error: SdA.py: patch does not apply
Your edited hunk does not apply. Edit again (saying "no" discards!) [y/n]?
Mmkay... git add --interactive "Your edited hunk does not apply"和如何阅读git diff的输出?解释了我必须更新受影响的行号。现在,我可以手动计算并说:“嗯,我已经删除了1、2、3……23行。我之前正在编辑74行,现在我正在编辑……嗯……希望我有一个计算器......51行”(“哇,我出汗了”)。
这似乎是一种过于复杂的方法。我仍然认为补丁是正确的方法,但如果我需要手动更新文件中受影响的行数,那么我肯定做错了什么。有没有人有更轻松、更高效的建议?