8

所以,我有一个我一直在分支 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()

+

没关系。底部有一个迷你指南。我明白了。因此,我们希望将新函数放入此提交中,并将其他函数的文档放入另一个提交中。根据迷你文档:# To remove '+' lines, delete them.

# 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]?

嗯... git add --interactive “您编辑的块不适用”以及如何读取 git diff 的输出?说明我必须更新受影响的行号。为此,现在,我可以手动计数并说“嗯,我删除了 1、2、3……23 行。我之前编辑了 74 行,现在我正在编辑……嗯……希望我有一个计算器...... 51 行”(“哇,我出汗了”)

这似乎是一种过于复杂的方法。我仍然认为补丁是正确的方法,但是如果我需要手动更新目标文件中受影响的行数,我一定是做错了。有人对如何更轻松有效地做到这一点有任何建议吗?

4

2 回答 2

7

用 注释掉要删除的行#,而不是删除它们,解决了这个问题。我不确定该行为是否是 emacs 的一部分,但评论一行实际上会减少补丁消息顶部的计数器。我发现另一个有用的功能是s先拆分大块,然后单独添加每个块。在这个特定的示例中,这将是更好的解决方案。

于 2013-07-30T00:55:33.810 回答
1

有 Git GUI 可以很容易地选择性地暂存行,您所要做的就是选择单独的行并添加它们,无需手动编辑大块。

两个这样的 GUI 是SourceTreeGit Cola

于 2013-07-24T03:43:20.280 回答