使用git add手动编辑--patch

使用git add手动编辑--patch,git,version-control,git-add,git-patch,Git,Version Control,Git Add,Git Patch,所以,我有一个文件,我一直在分支a工作,我正准备提交它。但是,看看差异,我认为最好将其放入两个单独的提交中,在本例中,可能是两个单独的分支。我以前用过GitAdd-patch来制作独立的大块头,所以我想我可以用这个。问题是,我需要把我的一个大块头分开。运行git add-patch SdA.py并使用e编辑问题块 # Manual hunk edit mode -- see bottom for a quick guide @@ -50,13 +50,74 @@ import PIL.Image

所以,我有一个文件,我一直在分支a工作,我正准备提交它。但是,看看差异,我认为最好将其放入两个单独的提交中,在本例中,可能是两个单独的分支。我以前用过GitAdd-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()

+
没关系。底部有一个迷你指南。我明白了。因此,我们希望将新函数放入此提交中,并将其他函数的文档放入另一个提交中。根据小文档:要删除“+”行,请删除它们

看起来不错。让我们加上那只小狗

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]?
嗯,凯。。。并解释我必须更新受影响的行号。要做到这一点,现在,我可以手动计数并说,嗯,我已经删除了1,2,3。。。23行。我以前编辑了74行,现在我正在编辑。。。隐马尔可夫模型。。。但愿我有一台计算器。。。。51行“呼,我出汗了”


这似乎是一种过于复杂的方法。我仍然认为修补程序是正确的方法,但如果我需要手动更新to文件中受影响行的数量,我肯定是做错了什么。有人对如何更轻松、更高效地完成这项工作有什么建议吗?

有一些Git GUI可以让你很容易地有选择地展示行,你所要做的就是选择单个行并添加它们,而无需手动编辑行


两个这样的GUI是and。

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

我有点不喜欢GUI,因为我觉得它们给大多数东西添加了不必要的抽象。这可能是好的也可能是坏的。对于复杂的操作,GUI变成了一种工具,而且可能比我以前做的要好得多。然而,对于简单的操作,我觉得这个补丁是一个简单的操作,我认为命令行应该是首选。我会等几天,看看有没有其他答案。不过,谢谢你的建议。@Phox为了它的价值,我几乎完全从命令行使用Git,但对于选择性登台,我的经验是GUI使它更快更简单。+1对于Git-cola,我已经在linux上寻找该功能一段时间了,我经常使用git-add-p,但由于某些原因,s不能很好地工作。这根本不能回答问题。这个问题与CLI-git有关,CLI-git是一个合适的客户机,不管其他工具如何比较,都有一种方法可以做到这一点。这对我来说非常有用,尽管没有计数器会自动递减
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]?