2013-07-24 43 views
3

所以,我有一個文件,我一直在分支A上工作,而且我準備好提交它。然而,看看diff,我認爲最好把它分成兩個單獨的提交(好吧,在這種情況下,可能是兩個獨立的分支)。我之前使用過git add --patch來分割不同的宏塊,所以我想我可以使用它。問題是,我需要分裂我的一塊錢。運行git add --patch SdA.py使用e編輯問題猛男......使用git添加手動編輯--patch <filename>

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

Mmkay ... git add --interactive "Your edited hunk does not apply"How to read the output from git diff?解釋,我必須更新受影響的行號。要做到這一點,我現在可以手動計數並說出「嗯,我已經刪除了1,2,3 ... 23行。我之前正在編輯74行,現在我正在編輯...嗯...希望我有一個計算器...... .... 51行「('哇,我汗')

這似乎是一個過於複雜的方法。我仍然認爲修補程序是正確的方法,但是如果我需要手動更新目標文件中受影響行的數量,我必須做錯。任何人有任何建議如何更容易和更有效地做到這一點?

回答

4

註釋掉#而不是刪除它們可以解決這個問題。我不確定該行爲是否爲emacs的一部分,但註釋一行實際上會減少補丁消息頂部的計數器。我發現有用的另一個功能是使用s首先分裂大塊,然後獨立地添加每個。在這個特定的例子中,這將是更好的解決方案。

2

有Git的圖形用戶界面,可以很容易地選擇舞臺線,所有你需要做的是選擇單獨的行並添加它們,不需要手動編輯人羣。

兩個這樣的GUI是SourceTreeGit Cola

+2

我對GUI很反感,因爲我覺得它們給大多數事物添加了不必要的抽象。這可以是好的也可以是壞的。對於複雜的操作,GUI變成了一種工具,並且可能比我所能做到的要好得多。然而,對於簡單的操作(我覺得這個補丁是一個簡單的操作),我認爲命令行應該是首選。我會在這幾天等待,看看是否有其他答案。但是,謝謝你的建議。 –

+0

@Phox對於它的價值,我幾乎完全從命令行使用Git,但對於選擇性登臺,我的經驗是GUI使它更快更簡單。 – 2013-07-25 01:31:08

+0

爲git-cola +1,我一直在尋找這個功能的Linux一段時間,我經常使用git add -p,但由於某些原因,「s」不能正常工作。 – nemesisdesign