8

これで、ブランチ A で作業していたファイルができました。これをコミットする準備が整いました。ただし、差分を見ると、2 つの別々のコミット (この場合は 2 つの別々のブランチ) に分けた方がよいと思います。以前に個別のハンクをステージングするために git add --patch を使用したことがあるので、これを使用できると思いました。問題は、ハンクの 1 つを分割する必要があることです。問題のハンクを編集するために実行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行」

これは非常に複雑な方法のようです。私はまだパッチが正しいアプローチだと思っていますが、to-file で影響を受ける行の数を手動で更新する必要がある場合は、何か間違ったことをしているに違いありません。これをより簡単かつ効率的に行う方法について何かアドバイスはありますか?

4

2 に答える 2

7

削除する行を削除するので#はなく、 でコメントアウトすると、この問題は解決します。この動作が emacs の一部であるかどうかは定かではありませんが、行にコメントを付けると、実際にはパッチ メッセージの上部にあるカウンターが減少します。私が便利だと思ったもう 1 つの機能はs、最初にハンクを分割し、次にそれぞれを個別に追加するために使用することでした。この特定の例では、それがより良い解決策でした。

于 2013-07-30T00:55:33.810 に答える
1

行を選択的にステージングすることを非常に簡単にする Git GUI があります。個々の行を選択して追加するだけで、ハンクを手動で編集する必要はありません。

そのような 2 つの GUI はSourceTreeGit Colaです。

于 2013-07-24T03:43:20.280 に答える