我跑了:
git add -p
然后我想通过键入s
以下内容来分割我的大块头:
import org.hamcrest.CoreMatchers; -import org.junit.Ignore; +import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; Stage this hunk [y,n,q,a,d,j,J,g,/,e,?]? s Sorry, cannot split this hunk
我只想添加import org.junit.Before;
到我的提交而不删除import org.junit.Ignore;
。我该怎么做?
您可以输入以下内容来手动编辑该块e
,然后对其进行编辑,以使其仅包含所需的内容(请注意所有导入之前的空格,但要添加的除外):
# Manual hunk edit mode -- see bottom for a quick guide. @@ -1,5 +1,5 @@ import org.hamcrest.CoreMatchers; import org.junit.Ignore; +import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired;
这样,您将获得:
+import org.junit.Before;
将在暂存区中,随时可以提交(参见git diff --cached
)
-import org.junit.Ignore;
将在工作目录中,可以添加到暂存区或进行更改(请参阅参考资料git diff
)。
提交后,您HEAD
将显示(即git show HEAD
):
commit f2d890ec808c4ef35a4e77b7929bcfbc233101b4 (HEAD -> master) Author: xxx Date: Thu Jul 4 19:49:25 2019 +0100 Second diff --git a/file.txt b/file.txt index d1d0b87..462d075 100644 --- a/file.txt +++ b/file.txt @@ -1,5 +1,6 @@ import org.hamcrest.CoreMatchers; import org.junit.Ignore; +import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired;